Skip to content

Commit

Permalink
add workspace config
Browse files Browse the repository at this point in the history
  • Loading branch information
dzencot committed Jul 11, 2024
1 parent 1e08ba5 commit b80388a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import fs from 'fs';
import path from 'path';

import fs from 'node:fs';
import path from 'node:path';
import _ from 'lodash';
import { fromMarkdown } from 'mdast-util-from-markdown';
import { toMarkdown } from 'mdast-util-to-markdown'
Expand All @@ -10,6 +10,7 @@ import {
formatMessage,
parseCheckedResult,
printFixResult,
getIgnoredWordsInWorkspace,
} from './utils.js';

import { check } from './languageToolApi.js';
Expand All @@ -22,11 +23,13 @@ const filterBlocks = [

const errorDelimeter = '\n------------------------\n';

/* TODO перенести получение слов для фильтра */
const filterWordsContent = fs.readFileSync('ignore_dictionary.txt', 'utf-8');
const filterWords = filterWordsContent.split(/\n/).map((word) => word.toLowerCase());

const isFiltered = (word) => {
if (filterWords.includes(word.toLowerCase())) {

const isFiltered = (word, additionalWords = []) => {
if ([...filterWords, ...additionalWords].includes(word.toLowerCase())) {
return true;
}

Expand Down Expand Up @@ -141,6 +144,8 @@ const fix = async (dirPath, language, rules = []) => {
const getErrors = async (dirPath, language, rules = []) => {
const filePaths = await getFilePaths(dirPath);

const wrongWords = getIgnoredWordsInWorkspace('/content/.vscode/settings.json');

const promises = filePaths.map(async (fullpath) => {
const sourceContent = fs.readFileSync(fullpath, 'utf-8');

Expand All @@ -158,7 +163,7 @@ const getErrors = async (dirPath, language, rules = []) => {
const lineNumber = leftPart.split('\n').length;
const word = content.slice(offset, offset + length);

if (isFiltered(word)) {
if (isFiltered(word, wrongWords)) {
return null;
}

Expand Down
12 changes: 12 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import fs from 'node:fs';
import clc from 'cli-color';
import _ from 'lodash';
import { glob } from 'glob';
Expand Down Expand Up @@ -59,4 +60,15 @@ export const printFixResult = (previousContent, currentContent, fileName) => {
console.log(`-------------------${fileName} done -----------------`);
};

export const getIgnoredWordsInWorkspace = (path) => {
if (!fs.existsSync(path)) {
return [];
}

const content = fs.readFileSync(path, 'utf-8');
const parsed = JSON.parse(content);

return parsed['languageToolLinter.languageTool.ignoredWordsInWorkspace'] || [];
};

export const getLanguageToolVersion = '6.4';

0 comments on commit b80388a

Please sign in to comment.