Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-412 Rewrite count-rules into ESM format #4911

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' } })),
);
}