Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(eslint-plugin-internal): add plugin-test-formatting rule (#1821)
The strings that are used for eslint plugins will not be checked for formatting.
This can lead to diff noise as one contributor adjusts formatting, uses different quotes, etc.

This rule just enforces the following:
- all code samples are formatted with prettier
- all single line tests do not use backticks
- all multiline tests have:
  - no code on the first line
  - no code on the last line
  - the closing backtick indentation === property indentation
  - one of the following indentations:
    - no indentation at all
    - indentation of 1 + object indent

examples of enforced style:
```ts
ruleTester.run('foo', rule, {
  valid: [
    'const a = 1;',
    `
      const a = 1;
    `,
    `
const a = 1;
    `,
    {
      code: 'const a = 1;',
    },
    {
      code: `
        const a = 1;
      `,
    },
    {
      code: `
const a = 1;
      `,
    },
  ],
  invalid: [
    {
      code: 'const a = 1;',
    },
    {
      code: `
        const a = 1;
      `,
    },
    {
      code: `
const a = 1;
      `,
    },
  ],
});
```
  • Loading branch information
bradzacher committed Mar 30, 2020
1 parent 151f89b commit 9b0023a
Show file tree
Hide file tree
Showing 7 changed files with 1,045 additions and 3 deletions.
1 change: 1 addition & 0 deletions .prettierrc.json
@@ -1,3 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
3 changes: 2 additions & 1 deletion packages/eslint-plugin-internal/package.json
Expand Up @@ -12,6 +12,7 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "2.26.0"
"@typescript-eslint/experimental-utils": "2.26.0",
"prettier": "*"
}
}
2 changes: 2 additions & 0 deletions packages/eslint-plugin-internal/src/rules/index.ts
@@ -1,9 +1,11 @@
import noTypescriptDefaultImport from './no-typescript-default-import';
import noTypescriptEstreeImport from './no-typescript-estree-import';
import pluginTestFormatting from './plugin-test-formatting';
import preferASTTypesEnum from './prefer-ast-types-enum';

export default {
'no-typescript-default-import': noTypescriptDefaultImport,
'no-typescript-estree-import': noTypescriptEstreeImport,
'plugin-test-formatting': pluginTestFormatting,
'prefer-ast-types-enum': preferASTTypesEnum,
};

0 comments on commit 9b0023a

Please sign in to comment.