Skip to content

Commit

Permalink
fix: most eslint rules have moved to @Stylistic (#1507)
Browse files Browse the repository at this point in the history
ESLint has moved most of it's style-related linter rules to a namespace
called `@stylistic`.

Update our built-in linter rules to reference those rules in the new
package name, and change the public interface to accept arbitrary
strings, instead of an enum from a specific set of rules.
  • Loading branch information
rix0rrr authored Dec 18, 2024
1 parent d5c4f2b commit 76fa496
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const repo = new YarnMonorepo({
'eslint',
'@typescript-eslint/parser@^6',
'@typescript-eslint/eslint-plugin@^6',
'@stylistic/eslint-plugin@^2',
'eslint-plugin-import',
],
vscodeWorkspace: true,
Expand Down
1 change: 1 addition & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions packages/@cdklabs/typewriter/src/eslint-rules.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* All Eslint rules that typewriter can disable.
*/
export enum EsLintRules {
COMMA_DANGLE = '@typescript-eslint/comma-dangle',
COMMA_SPACING = 'comma-spacing',
QUOTE_PROPS = 'quote-props',
QUOTES = 'quotes',
PRETTIER_PRETTIER = 'prettier/prettier',
MAX_LEN = 'max-len',
export class EsLintRules {
public static readonly COMMA_DANGLE = '@stylistic/comma-dangle';
public static readonly COMMA_SPACING = '@stylistic/comma-spacing';
public static readonly QUOTE_PROPS = '@stylistic/quote-props';
public static readonly QUOTES = '@stylistic/quotes';
public static readonly PRETTIER_PRETTIER = 'prettier/prettier';
public static readonly MAX_LEN = '@stylistic/max-len';
}
4 changes: 2 additions & 2 deletions packages/@cdklabs/typewriter/src/renderer/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ export interface TypeScriptRenderOptions extends RenderOptions {
*
* @default: max-len, prettier/prettier
*/
disabledEsLintRules?: EsLintRules[];
disabledEsLintRules?: string[];
}

export class TypeScriptRenderer extends Renderer {
private disabledEsLintRules: EsLintRules[];
private disabledEsLintRules: string[];
public constructor(options: TypeScriptRenderOptions = {}) {
super(options);

Expand Down
10 changes: 5 additions & 5 deletions packages/@cdklabs/typewriter/test/comments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('statements', () => {
fn.addBody(code.comment('test comment'));

expect(renderer.render(scope)).toMatchInlineSnapshot(`
"/* eslint-disable prettier/prettier, max-len */
"/* eslint-disable prettier/prettier, @stylistic/max-len */
// @ts-ignore TS6133
function freeFunction(): void {
// test comment
Expand All @@ -32,7 +32,7 @@ describe('statements', () => {
fn.addBody(code.commentOn(code.stmt.ret(code.expr.lit(1)), 'test comment'));

expect(renderer.render(scope)).toMatchInlineSnapshot(`
"/* eslint-disable prettier/prettier, max-len */
"/* eslint-disable prettier/prettier, @stylistic/max-len */
// @ts-ignore TS6133
function freeFunction(): void {
// test comment
Expand All @@ -51,7 +51,7 @@ describe('expressions', () => {
fn.addBody(code.stmt.ret(code.commentOn(code.expr.lit(1), 'test comment')));

expect(renderer.render(scope)).toMatchInlineSnapshot(`
"/* eslint-disable prettier/prettier, max-len */
"/* eslint-disable prettier/prettier, @stylistic/max-len */
// @ts-ignore TS6133
function freeFunction(): void {
return /* test comment */ 1;
Expand All @@ -75,7 +75,7 @@ describe('expressions', () => {
);

expect(renderer.render(scope)).toMatchInlineSnapshot(`
"/* eslint-disable prettier/prettier, max-len */
"/* eslint-disable prettier/prettier, @stylistic/max-len */
// @ts-ignore TS6133
function freeFunction(): void {
return ["foo", /* test comment */ "bar", "baz"];
Expand All @@ -91,7 +91,7 @@ describe('expressions', () => {
fn.addBody(code.stmt.ret(code.commentOn($E(code.expr.lit(1)).convertToString(), 'test comment')));

expect(renderer.render(scope)).toMatchInlineSnapshot(`
"/* eslint-disable prettier/prettier, max-len */
"/* eslint-disable prettier/prettier, @stylistic/max-len */
// @ts-ignore TS6133
function freeFunction(): void {
return /* test comment */ 1.convertToString();
Expand Down
6 changes: 3 additions & 3 deletions packages/@cdklabs/typewriter/test/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('functions', () => {
});

expect(renderer.render(scope)).toMatchInlineSnapshot(`
"/* eslint-disable prettier/prettier, max-len */
"/* eslint-disable prettier/prettier, @stylistic/max-len */
// @ts-ignore TS6133
function freeFunction(): void;"
`);
Expand All @@ -27,7 +27,7 @@ describe('functions', () => {
});

expect(renderer.render(scope)).toMatchInlineSnapshot(`
"/* eslint-disable prettier/prettier, max-len */
"/* eslint-disable prettier/prettier, @stylistic/max-len */
// @ts-ignore TS6133
export function freeFunction(): void;"
`);
Expand All @@ -40,7 +40,7 @@ describe('functions', () => {
});

expect(renderer.render(scope)).toMatchInlineSnapshot(`
"/* eslint-disable prettier/prettier, max-len */
"/* eslint-disable prettier/prettier, @stylistic/max-len */
// @ts-ignore TS6133
function freeFunction(): void;"
`);
Expand Down
2 changes: 1 addition & 1 deletion packages/@cdklabs/typewriter/test/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('expression proxy', () => {
fn.addBody(code.stmt.ret($E(code.expr.lit(1)).convertToString()));

expect(renderer.render(scope)).toMatchInlineSnapshot(`
"/* eslint-disable prettier/prettier, max-len */
"/* eslint-disable prettier/prettier, @stylistic/max-len */
// @ts-ignore TS6133
function freeFunction(): string {
return 1.convertToString();
Expand Down
10 changes: 6 additions & 4 deletions packages/@cdklabs/typewriter/test/ts-rendering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ beforeEach(() => {
describe('eslint rules', () => {
test('prettier/prettier and max-len are disabled by default', () => {
const renderer = new TypeScriptRenderer();
expect(renderer.render(scope)).toMatchInlineSnapshot(`"/* eslint-disable prettier/prettier, max-len */"`);
expect(renderer.render(scope)).toMatchInlineSnapshot(
`"/* eslint-disable prettier/prettier, @stylistic/max-len */"`,
);
});

test('max-len can be explicitly disabled without disabling prettier/prettier', () => {
const renderer = new TypeScriptRenderer({ disabledEsLintRules: [EsLintRules.MAX_LEN] });
expect(renderer.render(scope)).toMatchInlineSnapshot(`"/* eslint-disable max-len */"`);
expect(renderer.render(scope)).toMatchInlineSnapshot(`"/* eslint-disable @stylistic/max-len */"`);
});

test('A single eslint rule can be disabled', () => {
const renderer = new TypeScriptRenderer({ disabledEsLintRules: [EsLintRules.COMMA_DANGLE] });
expect(renderer.render(scope)).toMatchInlineSnapshot(`"/* eslint-disable @typescript-eslint/comma-dangle */"`);
expect(renderer.render(scope)).toMatchInlineSnapshot(`"/* eslint-disable @stylistic/comma-dangle */"`);
});

test('many eslint rules can be disabled', () => {
Expand All @@ -35,7 +37,7 @@ describe('eslint rules', () => {
],
});
expect(renderer.render(scope)).toMatchInlineSnapshot(
`"/* eslint-disable @typescript-eslint/comma-dangle, comma-spacing, max-len, prettier/prettier, quotes, quote-props */"`,
`"/* eslint-disable @stylistic/comma-dangle, @stylistic/comma-spacing, @stylistic/max-len, prettier/prettier, @stylistic/quotes, @stylistic/quote-props */"`,
);
});

Expand Down
20 changes: 18 additions & 2 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 76fa496

Please sign in to comment.