Skip to content

Commit

Permalink
chore(tools): adjust eslint rule generator
Browse files Browse the repository at this point in the history
  • Loading branch information
mainframev committed Jul 24, 2024
1 parent f2900a2 commit 81a783f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RuleTester } from '@typescript-eslint/rule-tester';
import { rule, RULE_NAME } from './<%= name %>';

const ruleTester = new RuleTester();

ruleTester.run(RULE_NAME, rule, {
valid: [`const example = true;`],
invalid: [],
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ describe('eslint-rule generator', () => {
`);

expect(tree.read(paths.spec, 'utf-8')).toMatchInlineSnapshot(`
"import { TSESLint } from '@typescript-eslint/utils';
"import { RuleTester } from '@typescript-eslint/rule-tester';
import { rule, RULE_NAME } from './uppercase';
const ruleTester = new TSESLint.RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
});
const ruleTester = new RuleTester();
ruleTester.run(RULE_NAME, rule, {
valid: [\`const example = true;\`],
Expand Down
12 changes: 11 additions & 1 deletion tools/workspace-plugin/src/generators/eslint-rule/generator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { formatFiles, Tree } from '@nx/devkit';
import { formatFiles, Tree, joinPathFragments, readProjectConfiguration, generateFiles } from '@nx/devkit';
import { EslintRuleGeneratorSchema } from './schema';
import { lintWorkspaceRuleGenerator } from '@nx/eslint/src/generators/workspace-rule/workspace-rule';

export async function eslintRuleGenerator(tree: Tree, schema: EslintRuleGeneratorSchema) {
const options = normalizeSchema(schema);
await lintWorkspaceRuleGenerator(tree, options);

const project = readProjectConfiguration(tree, 'eslint-rules');
const templateSource = joinPathFragments(__dirname, 'files');

tree.delete(joinPathFragments(project.root, joinPathFragments(options.directory, `${options.name}.spec.ts`)));

generateFiles(tree, templateSource, joinPathFragments(project.root, options.directory), {
...options,
tmpl: '',
});

await formatFiles(tree);
}

Expand Down

0 comments on commit 81a783f

Please sign in to comment.