Skip to content

Commit

Permalink
Revert "update"
Browse files Browse the repository at this point in the history
This reverts commit f6b3e70.
  • Loading branch information
dzencot committed Jul 3, 2024
1 parent f6b3e70 commit 14f0ec1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
19 changes: 5 additions & 14 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand Down Expand Up @@ -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));
});

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

Expand Down Expand Up @@ -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');
};
Expand All @@ -253,5 +254,4 @@ export {
formatErrors,
filterIgnoredErrors,
writeIgnoreErrorsFile,
errorDelimeter,
};

0 comments on commit 14f0ec1

Please sign in to comment.