smells-code-analyzer
Version:
CLI tool powered by LSP and tree-sitter for finding dead and smells code from your project
34 lines • 1.18 kB
JavaScript
import { rgPath } from '@vscode/ripgrep';
import { CancellationTokenSource, TextSearchEngineAdapter, } from 'ripgrep-wrapper';
import walkSync from 'walk-sync';
export async function filterFiles(config) {
const cts = new CancellationTokenSource();
const query = {
contentPattern: {
pattern: config.contentMatchingRegexp,
isRegExp: true,
},
folderQueries: [
{
folder: config.analyzeDirectory,
includePattern: { [config.fileMatchingRegexp]: true },
excludePattern: config.fileExcludeRegexps?.reduce((acc, reg) => {
return { ...acc, [reg]: true };
}, {}),
},
],
};
const searchEngine = new TextSearchEngineAdapter(rgPath, query);
const result = [];
await searchEngine.search(cts.token, (res) => {
result.push(...res.map((r) => r.path));
}, () => { });
return result;
}
export function filesCount(config) {
const paths = walkSync(config.analyzeDirectory, {
globs: [config.fileMatchingRegexp],
});
return paths.length;
}
//# sourceMappingURL=filter-files.js.map