Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin-internal): add plugin-test-formatting rule #1821

Merged
merged 2 commits into from Mar 30, 2020

Conversation

bradzacher
Copy link
Member

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:

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;
      `,
    },
  ],
});

@bradzacher bradzacher added the repo maintenance things to do with maintenance of the repo, and not with code/docs label Mar 30, 2020
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @bradzacher!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@codecov
Copy link

codecov bot commented Mar 30, 2020

Codecov Report

Merging #1821 into master will decrease coverage by 0.24%.
The diff coverage is 81.75%.

@@            Coverage Diff             @@
##           master    #1821      +/-   ##
==========================================
- Coverage   94.96%   94.71%   -0.25%     
==========================================
  Files         159      160       +1     
  Lines        7114     7251     +137     
  Branches     2035     2074      +39     
==========================================
+ Hits         6756     6868     +112     
- Misses        155      165      +10     
- Partials      203      218      +15     
Flag Coverage Δ
#unittest 94.71% <81.75%> (-0.25%) ⬇️
Impacted Files Coverage Δ
...lugin-internal/src/rules/plugin-test-formatting.ts 81.75% <81.75%> (ø)

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;
      `,
    },
  ],
});
```
@bradzacher bradzacher force-pushed the internal-lint-test-formatting branch from a6fcb8d to 51d563a Compare March 30, 2020 08:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
repo maintenance things to do with maintenance of the repo, and not with code/docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant