diff --git a/bin/run.js b/bin/run.js index 3e2b82e..1ce6245 100644 --- a/bin/run.js +++ b/bin/run.js @@ -2,15 +2,7 @@ import { exec } from 'child_process'; import fs from 'node:fs'; -import { - getErrors, - formatErrors, - getWrongWords, - fix, - filterIgnoredErrors, - writeIgnoreErrorsFile, - errorDelimeter, -} from '../src/index.js'; +import { getErrors, formatErrors, getWrongWords, fix, filterIgnoredErrors, writeIgnoreErrorsFile } from '../src/index.js'; import { getLanguageToolVersion } from '../src/utils.js'; import { Command } from 'commander'; const program = new Command(); @@ -31,10 +23,10 @@ program const ignorePath = options.ignore; const errors = await getErrors(dirPath, language, rules); - const formatedErrors = formatErrors(errors); - const filtered = filterIgnoredErrors(formatedErrors, ignorePath); + const filtered = filterIgnoredErrors(errors, ignorePath); if (filtered.length > 0) { - console.log(filtered.join(errorDelimeter)); + const formattedErrors = formatErrors(filtered); + console.log(formattedErrors.join('\n------------------------\n')); process.exit(1); } }, 5000)); @@ -85,8 +77,7 @@ program const language = options.language; const errors = await getErrors(dirPath, language, rules); - const formatedErrors = formatErrors(errors); - writeIgnoreErrorsFile(formatedErrors, filePath); + writeIgnoreErrorsFile(errors, filePath); }, 5000)); }); diff --git a/src/index.js b/src/index.js index 15ce22a..f03f107 100644 --- a/src/index.js +++ b/src/index.js @@ -20,8 +20,6 @@ const filterBlocks = [ 'inlineCode', ]; -const errorDelimeter = '\n------------------------\n'; - const filterWordsContent = fs.readFileSync('ignore_dictionary.txt', 'utf-8'); const filterWords = filterWordsContent.split(/\n/).map((word) => word.toLowerCase()); @@ -227,21 +225,24 @@ const formatError = (error) => { const formatErrors = (errors) => errors.map(formatError); -const filterIgnoredErrors = (formatedErrors, ignoreFilePath) => { +const filterIgnoredErrors = (errors, ignoreFilePath) => { if (!fs.existsSync(ignoreFilePath)) { - return formatedErrors; + return errors; } const ignoreContent = fs.readFileSync(ignoreFilePath, 'utf-8'); - const ignore = ignoreContent.split(errorDelimeter); + const ignore = ignoreContent.split(', '); - const result = formatedErrors.filter((error) => !ignore.includes(error)); + const result = errors.filter((error) => { + const lineError = getLineError(error) + return !ignore.includes(lineError); + }); return result; }; -const writeIgnoreErrorsFile = (formatedErrors, ignoreFilePath) => { - const result = formatedErrors.join(errorDelimeter); +const writeIgnoreErrorsFile = (errors, ignoreFilePath) => { + const result = errors.map(getLineError).join(', '); fs.writeFileSync(ignoreFilePath, result, 'utf-8'); }; @@ -253,5 +254,4 @@ export { formatErrors, filterIgnoredErrors, writeIgnoreErrorsFile, - errorDelimeter, };