Skip to content

Commit

Permalink
Add script to count rules for README (#4409)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia-kebets-sonarsource authored Nov 22, 2023
1 parent 0d68574 commit 13a5cf2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This SonarSource project is a [static code analyzer](https://en.wikipedia.org/wi
# Features

- Advanced rules based on pattern matching and control flow analysis
- [370 JS rules](https://rules.sonarsource.com/javascript) and [375 TS rules](https://rules.sonarsource.com/typescript)
- [25 CSS rules](https://rules.sonarsource.com/css)
- [389 JS rules](https://rules.sonarsource.com/javascript) and [393 TS rules](https://rules.sonarsource.com/typescript)
- [26 CSS rules](https://rules.sonarsource.com/css)
- Compatible with ECMAScript 2015-2020
- React JSX, Flow, Vue, and AWS lambda functions support for JavaScript and TypeScript
- CSS, SCSS, SASS, Less, also 'style' inside HTML and VueJS files
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"td": "node typedoc/scripts/setup-plugins.js && ./node_modules/.bin/typedoc --options typedoc/typedoc.js",
"prepare": "husky install",
"precommit": "pretty-quick --staged",
"count-rules": "node tools/count-rules.js",
"_:bridge:clear": "rimraf lib/*",
"_:plugin:prepare-bridge": "npm pack && node tools/check-distribution-filepath-length.js && npm run _:plugin:copy-bridge",
"_:plugin-fetch-node": "node tools/fetch-node/scripts/wrapper.mjs",
Expand Down
53 changes: 53 additions & 0 deletions tools/count-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const url = require('node:url');
const path = require('node:path');
const fs = require('node:fs');

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

const jsTsRules = getJsonFiles(pathToJsTsRules);

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

const cssRules = 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}`);

function getJsonFiles(pathToRules) {
const filenames = fs.readdirSync(pathToRules);
return filenames
.filter(filename => filename.endsWith('.json') && filename.length <= 'S1234.json'.length)
.map(file => require(path.join(pathToRules, file)));
}

0 comments on commit 13a5cf2

Please sign in to comment.