Skip to content

Commit

Permalink
Allow comment-based fixtures to be named *.fixture.<ext> instead of…
Browse files Browse the repository at this point in the history
… `cb.fixture.<ext>` (#4099)
  • Loading branch information
yassin-kammoun-sonarsource committed Aug 24, 2023
1 parent 781954d commit 4d2c5ec
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/jsts/src/rules/S1128/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ ruleTesterTS.run('Unnecessary imports should be removed', rule, {
],
});

const project = path.join(__dirname, 'tsconfig.fixture.json');
const filename = path.join(__dirname, 'unit.fixture.tsx');
const project = path.join(__dirname, 'fixtures', 'tsconfig.fixture.json');
const filename = path.join(__dirname, 'fixtures', 'unit.fixture.tsx');

const ruleTesterJsxFactory = new RuleTester({
parserOptions: {
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions packages/jsts/src/rules/tsconfig.cb.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"allowJs": true
},
"include": [
"**/cb.fixture.js",
"**/cb.fixture.jsx",
"**/cb.fixture.ts",
"**/cb.fixture.tsx",
"**/cb.fixture.vue"
"**/*.fixture.js",
"**/*.fixture.jsx",
"**/*.fixture.ts",
"**/*.fixture.tsx",
"**/*.fixture.vue"
]
}
10 changes: 5 additions & 5 deletions packages/jsts/tests/tools/testers/comment-based/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ const ruleTester = new RuleTester({ parser: __filename });

/**
* Checks that a rule raises the issues declared as comment-based expectations on fixture files.
* These fixtures are to be found in the rule directory and should be named as `cb.fixture.<ext>`.
* These fixtures are to be found in the rule directory and should be named as `*.fixture.<ext>`.
* The directory can include options (`cb.options.json`) to configure the rule behaviour.
*/
export function check(ruleId: string, ruleModule: Rule.RuleModule, ruleDir: string) {
const fixtures = [];
['js', 'ts', 'jsx', 'tsx', 'vue'].forEach(ext => {
const fixture = path.join(ruleDir, `cb.fixture.${ext}`);
if (fs.existsSync(fixture)) {
for (const file of fs.readdirSync(ruleDir)) {
if (file.match(/\.fixture\.(js|ts|jsx|tsx|vue)$/)) {
const fixture = path.join(ruleDir, file);
fixtures.push(fixture);
}
});
}

for (const fixture of fixtures) {
const code = fs.readFileSync(fixture, { encoding: 'utf8' }).replace(/\r?\n|\r/g, '\n');
Expand Down

0 comments on commit 4d2c5ec

Please sign in to comment.