Skip to content

Commit

Permalink
fix tests and eslint plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiez committed Nov 25, 2024
1 parent f980c2d commit cf8f4a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 0 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ eslint_plugin_test_task:
- . ~/.profile
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- npm install -g tsx
- npm run eslint-plugin:build
- cd its/eslint8-plugin-sonarjs
- npm install
Expand Down Expand Up @@ -337,7 +336,6 @@ eslint8_node16_plugin_test_task:
- . ~/.profile
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- npm install -g tsx
- npm run eslint-plugin:build
- cd its/eslint8-plugin-sonarjs
- npm install
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"ruling-sync": "rsync -avh packages/ruling/tests/actual/jsts/ its/ruling/src/test/expected/jsts/ --delete",
"update-ruling-data": "mvn -f sonar-plugin/sonar-javascript-plugin/pom.xml compile && npx tsx packages/ruling/tests/tools/parseRulesData.ts",
"create-rule-indexes": "tsx tools/generate-rule-indexes.ts",
"bridge:compile": "npm run create-rule-indexes && tsc -b packages profiling && npm run _:bridge:copy-protofiles",
"bridge:compile": "tsc -b packages profiling && npm run _:bridge:copy-protofiles",
"bridge:test": "tsx --tsconfig packages/tsconfig.test.json --test --test-reporter spec --test-reporter-destination stdout \"packages/*/src/rules/*[!node_modules]/**/*.test.ts\" \"packages/*[!ruling]/tests/**/*.test.ts\"",
"bridge:test:cov": "odz run npm run bridge:test || true && odz report --reporters=text-lcov > lcov.info",
"bridge:bundle": "node esbuild.mjs",
Expand All @@ -29,7 +29,7 @@
"plugin:build:fast": "mvn install -DskipTests && npm run update-ruling-data",
"pbf": "npm run plugin:build:fast",
"td": "npm --prefix typedoc/searchable-parameters-plugin run setup && npx typedoc --options typedoc/typedoc.js",
"prepare": "husky install",
"prepare": "husky install && npm run create-rule-indexes",
"precommit": "pretty-quick --staged",
"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",
Expand All @@ -38,7 +38,7 @@
"_:plugin-fetch-node": "node tools/fetch-node/scripts/wrapper.mjs",
"_:plugin:pre-build": "npm run _:plugin:prepare-bridge && npm run _:plugin-fetch-node",
"_:plugin:copy-bridge": "cpy sonarjs-1.0.0.tgz sonar-plugin/sonar-javascript-plugin/target/classes && cpy sonarjs-1.0.0.tgz sonar-plugin/standalone/target/classes",
"eslint-plugin:build": "npm run create-rule-indexes && npm ci && npm run eslint-plugin:compile && cd lib && npm pack",
"eslint-plugin:build": "npm ci && npm run eslint-plugin:compile && cd lib && npm pack",
"eslint-plugin:compile": "npm run _:bridge:clear && npm run eslint-plugin:check && npm run eslint-plugin:emit && npm run eslint-plugin:types && npm run eslint-plugin:package-json && npm run eslint-plugin:copy-assets",
"eslint-plugin:check": "tsc -p tsconfig-plugin.json --noEmit",
"eslint-plugin:emit": "tsc -p tsconfig-plugin.json --noCheck --module commonjs --moduleResolution node --outDir lib/cjs",
Expand Down
22 changes: 11 additions & 11 deletions packages/jsts/tests/rules/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

import { configs, rules, meta } from '../../src/rules/plugin.js';
import { configs, meta } from '../../src/rules/plugin.js';
import fs from 'fs';
import path from 'path';
import { valid } from 'semver';
import { describe, it } from 'node:test';
import { expect } from 'expect';
import { pathToFileURL } from 'node:url';

const mappedRules = new Map(
Object.entries(rules).map(([eslintId, rule]) => [rule.meta.docs.url, eslintId]),
);

describe('Plugin public API', () => {
it('should map keys to rules definitions', async () => {
const ruleFolder = path.join(import.meta.dirname, '../../src/rules');
const sonarKeys = fs.readdirSync(ruleFolder).filter(name => /^S\d+/.test(name));
const ruleIds = fs.readdirSync(ruleFolder).filter(name => /^S\d+/.test(name));
const missing = [];
for (const sonarKey of sonarKeys) {
for (const ruleId of ruleIds) {
const { meta, implementation, eslintId, sonarKey } = await import(
pathToFileURL(path.join(ruleFolder, ruleId, 'meta.js')).toString()
);
expect(sonarKey).toEqual(ruleId);
expect(['original', 'decorated', 'external']).toContain(implementation);
if (implementation !== 'original') {
continue;
}
const { rule } = await import(
pathToFileURL(path.join(ruleFolder, sonarKey, 'index.js')).toString()
);
expect(rule.meta.docs!.url).toBe(
`https://sonarsource.github.io/rspec/#/rspec/${sonarKey}/javascript`,
);
const { meta } = await import(
pathToFileURL(path.join(ruleFolder, sonarKey, 'meta.js')).toString()
);
const eslintId = mappedRules.get(rule.meta.docs.url);
if (!eslintId) {
missing.push(sonarKey);
} else {
Expand Down

0 comments on commit cf8f4a5

Please sign in to comment.