Skip to content

Commit

Permalink
JS-412 Rewrite count-rules into ESM format (#4911)
Browse files Browse the repository at this point in the history
  • Loading branch information
zglicz authored Nov 20, 2024
1 parent b00b935 commit f5a8914
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 54 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"td": "npm --prefix typedoc/searchable-parameters-plugin run setup && npx typedoc --options typedoc/typedoc.js",
"prepare": "husky install",
"precommit": "pretty-quick --staged",
"count-rules": "node tools/count-rules.cjs",
"count-rules": "node tools/count-rules.js",
"_:bridge:copy-protofiles": "cpy --flat packages/jsts/src/parsers/estree.proto sonar-plugin/bridge/src/main/protobuf && cpy --flat packages/jsts/src/parsers/estree.proto lib/jsts/src/parsers",
"_:bridge:clear": "rimraf --glob lib/*",
"_:plugin:prepare-bridge": "npm pack && node tools/check-distribution-filepath-length.cjs && npm run _:plugin:copy-bridge && npm run generate-rules-list",
Expand Down
53 changes: 0 additions & 53 deletions tools/count-rules.cjs

This file was deleted.

54 changes: 54 additions & 0 deletions tools/count-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import path from 'node:path';
import fs from 'node:fs/promises';

const pathToJsTsRules = path.join(
import.meta.dirname,
'..',
'sonar-plugin',
'javascript-checks',
'src',
'main',
'resources',
'org',
'sonar',
'l10n',
'javascript',
'rules',
'javascript',
);
const pathToCssRules = path.join(
import.meta.dirname,
'..',
'sonar-plugin',
'css',
'src',
'main',
'resources',
'org',
'sonar',
'l10n',
'css',
'rules',
'css',
);

const jsTsRules = await getJsonFiles(pathToJsTsRules);

const jsRules = jsTsRules.filter(rule => rule.default.compatibleLanguages.includes('JAVASCRIPT'));
const tsRules = jsTsRules.filter(rule => rule.default.compatibleLanguages.includes('TYPESCRIPT'));

const cssRules = await getJsonFiles(pathToCssRules);

console.log(`JS/TS rules: ${jsTsRules.length}`);
console.log(`JS rules: ${jsRules.length}`);
console.log(`TS rules: ${tsRules.length}`);
console.log(`CSS rules: ${cssRules.length}`);

async function getJsonFiles(pathToRules) {
const filenames = await fs.readdir(pathToRules);
return Promise.all(
filenames
.filter(filename => filename.endsWith('.json') && filename.length <= 'S1234.json'.length)
.map(async file => await import(path.join(pathToRules, file), { assert: { type: 'json' } })),
);
}

0 comments on commit f5a8914

Please sign in to comment.