Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dzencot committed Jul 3, 2024
1 parent 50af113 commit f6b3e70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
19 changes: 14 additions & 5 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

import { exec } from 'child_process';
import fs from 'node:fs';
import { getErrors, formatErrors, getWrongWords, fix, filterIgnoredErrors, writeIgnoreErrorsFile } from '../src/index.js';
import {
getErrors,
formatErrors,
getWrongWords,
fix,
filterIgnoredErrors,
writeIgnoreErrorsFile,
errorDelimeter,
} from '../src/index.js';
import { getLanguageToolVersion } from '../src/utils.js';
import { Command } from 'commander';
const program = new Command();
Expand All @@ -23,10 +31,10 @@ program
const ignorePath = options.ignore;

const errors = await getErrors(dirPath, language, rules);
const filtered = filterIgnoredErrors(errors, ignorePath);
const formatedErrors = formatErrors(errors);
const filtered = filterIgnoredErrors(formatedErrors, ignorePath);
if (filtered.length > 0) {
const formattedErrors = formatErrors(filtered);
console.log(formattedErrors.join('\n------------------------\n'));
console.log(filtered.join(errorDelimeter));
process.exit(1);
}
}, 5000));
Expand Down Expand Up @@ -77,7 +85,8 @@ program
const language = options.language;

const errors = await getErrors(dirPath, language, rules);
writeIgnoreErrorsFile(errors, filePath);
const formatedErrors = formatErrors(errors);
writeIgnoreErrorsFile(formatedErrors, filePath);
}, 5000));
});

Expand Down
18 changes: 9 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ 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());

Expand Down Expand Up @@ -225,24 +227,21 @@ const formatError = (error) => {

const formatErrors = (errors) => errors.map(formatError);

const filterIgnoredErrors = (errors, ignoreFilePath) => {
const filterIgnoredErrors = (formatedErrors, ignoreFilePath) => {
if (!fs.existsSync(ignoreFilePath)) {
return errors;
return formatedErrors;
}

const ignoreContent = fs.readFileSync(ignoreFilePath, 'utf-8');
const ignore = ignoreContent.split(', ');
const ignore = ignoreContent.split(errorDelimeter);

const result = errors.filter((error) => {
const lineError = getLineError(error)
return !ignore.includes(lineError);
});
const result = formatedErrors.filter((error) => !ignore.includes(error));

return result;
};

const writeIgnoreErrorsFile = (errors, ignoreFilePath) => {
const result = errors.map(getLineError).join(', ');
const writeIgnoreErrorsFile = (formatedErrors, ignoreFilePath) => {
const result = formatedErrors.join(errorDelimeter);

fs.writeFileSync(ignoreFilePath, result, 'utf-8');
};
Expand All @@ -254,4 +253,5 @@ export {
formatErrors,
filterIgnoredErrors,
writeIgnoreErrorsFile,
errorDelimeter,
};

0 comments on commit f6b3e70

Please sign in to comment.