Skip to content

Commit

Permalink
Fix CSpell file name linting does not use (custom) CSpell configurati…
Browse files Browse the repository at this point in the history
…on (#2148)

* Fix CSpell file name linting does not use (custom) CSpell configuration

Fixes #2058

* [MegaLinter] Apply linters fixes

Co-authored-by: nvuillam <nvuillam@users.noreply.github.com>
  • Loading branch information
nvuillam and nvuillam committed Dec 20, 2022
1 parent c13e920 commit a6fdbd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
- Upgrade to alpine 3.16
- Disable php7 & upgrade php8 tp php81
- Add Makefile linters to documentation flavor
- Fixes
- CSpell file name linting does not use (custom) CSpell configuration ([#2058](https://github.com/oxsecurity/megalinter/issues/2058))

- Linter versions upgrades
- [cspell](https://github.com/streetsidesoftware/cspell/tree/master/packages/cspell) from 6.14.3 to **6.15.0** on 2022-11-26
Expand Down
20 changes: 15 additions & 5 deletions megalinter/linters/CSpellLinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
import logging
import os
import re
import tempfile
import uuid

from megalinter import Linter, config, utils
from megalinter.constants import DEFAULT_REPORT_FOLDER_NAME


class CSpellLinter(Linter):
def __init__(self, params=None, linter_config=None):
self.temp_file_name = None
super().__init__(params, linter_config)

def build_lint_command(self, file=None) -> list:
# Create temp file with files segments
if (
Expand All @@ -27,17 +30,24 @@ def build_lint_command(self, file=None) -> list:
for file_path in self.files:
file_path = re.sub("[^0-9a-zA-Z]+", " ", os.path.splitext(file_path)[0])
file_names_txt += file_path + "\n"
temp_file_name = (
tempfile.gettempdir()
self.temp_file_name = (
self.workspace
+ os.path.sep
+ str(uuid.uuid4())
+ "-megalinter_file_names_cspell.txt"
)
with open(temp_file_name, "w", encoding="utf-8") as f:
with open(self.temp_file_name, "w", encoding="utf-8") as f:
f.write(file_names_txt)
self.files += [temp_file_name]
self.files += [self.temp_file_name]
return super().build_lint_command(file)

# Remove temp file with file names if existing
def execute_lint_command(self, command):
res = super().execute_lint_command(command)
if self.temp_file_name is not None:
os.remove(self.temp_file_name)
return res

# Provide additional details in text reporter logs
# noinspection PyMethodMayBeStatic
def complete_text_reporter_report(self, reporter_self):
Expand Down

0 comments on commit a6fdbd6

Please sign in to comment.