Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Add support for ESLint doc url meta, update dependencies, support TypeScript 2.7 #84

Merged
merged 24 commits into from
Mar 15, 2018

Conversation

kaelig
Copy link
Contributor

@kaelig kaelig commented Mar 13, 2018

Released under version 20.0.0.


  • Breaking: the version of TypeScript supported by this plugin is 2.7.x (in line with typescript-eslint-parser’s TypeScript support)
  • Updated dependencies that support the new ESLint documentation URL metadata. Errors from these plugins are accompanied by a link to the documentation for the broken rule.
  • Updated various other dependencies to their latest versions
  • Dependencies are now strictly versioned for tighter control over the exact rules the plugin enforces.
Package old new
eslint-plugin-ava ^4.4.0 4.5.1
eslint-plugin-import ^2.8.0 2.9.0
eslint-plugin-jest ^21.5.0 21.14.1
eslint-plugin-lodash ^2.5.0 2.6.1
eslint-plugin-node ^5.2.1 6.0.1
eslint-plugin-prettier ^2.4.0 2.6.0
eslint-plugin-promise ^3.6.0 3.7.0
eslint-plugin-react ^7.5.1 7.7.0
eslint-plugin-typescript ^0.8.1 0.10.0

@kaelig kaelig changed the title Add ESLint doc url meta Add ESLint doc url meta, update dependencies, support TypeScript 2.7 Mar 14, 2018
@kaelig
Copy link
Contributor Author

kaelig commented Mar 14, 2018

Request for comments

cc @lemonmade @ismail-syed @GoodForOneFare

jest/lowercase-name

I believe @lemonmade likes having tests that start with lowercase, so I turned on the new rule jest/lowercase-name, however it fails on this type of code:

describes should begin with lowercase

describe('ModuleConcatenationPlugin', () => {

Should I turn jest/lowercase-name back off?


jest/valid-describe

Fails on this code from sewing-kit:

No async describe callback

  describe('cache', async () => {
    it('always sets cacheing to true', async () => {
      expect(
        await webpackConfig(createWorkspace({env: client})),
      ).toHaveProperty('cache', true);
      expect(
        await webpackConfig(createWorkspace({env: server})),
      ).toHaveProperty('cache', true);
    });
  });

@GoodForOneFare any thoughts? Are async callbacks generally to be avoided or should we allow it?


jest/consistent-test-it

Fails on this code from sewing-kit:

Prefer using 'test' instead of 'it'

it('fails', () => {
  expect(true).toBe(false);
});

By default, the rule enforces test at the root of test files, and it when nested under describe.

Thoughts?

@kaelig kaelig changed the title Add ESLint doc url meta, update dependencies, support TypeScript 2.7 Add support for ESLint doc url meta, update dependencies, support TypeScript 2.7 Mar 14, 2018
@cartogram
Copy link
Contributor

cartogram commented Mar 14, 2018

Personally, I would prefer the jest/lowercase-name only be enforced on it and not describe (jest-community/eslint-plugin-jest#92). My guess is that would remove most of the failures.

Copy link
Member

@lemonmade lemonmade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Do we have to do something to have our own rules support he new doc links thing?

key: v1-npm-deps-{{ arch }}-{{ checksum "yarn.lock" }}
paths:
- node_modules
- run: yarn run check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably would have been better as a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I got a bit carried away 😅

svg: 'always',
png: 'always',
jpg: 'always',
ico: 'always',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also want .graphql/ .css/ .scss?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, addressed in d2f1785

@@ -17,4 +17,16 @@ module.exports = {
'jest/prefer-to-be-undefined': 'error',
// Ensure `expect()` is called with a single argument and there is an actual expectation made.
'jest/valid-expect': 'error',
// Suggest using expect.assertions() OR expect.hasAssertions()
'jest/valid-expect-in-promise': 'off',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are missing a rule (the above us not the correct description for the rule)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this rule should definitely be on, it’s a very common problem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this rule should definitely be on, it’s a very common problem

Turned on in 23be4b8

// Ensures the proper number of arguments are passed to Promise functions
'promise/valid-params': 'error',
// Avoid calling new on a Promise static method
'promise/no-new-statics': 'off',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason to leave this off

Copy link
Contributor Author

@kaelig kaelig Mar 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s already handled by another rule (no-new)

@@ -49,6 +51,8 @@ module.exports = {
'react/no-render-return-value': 'error',
// Prevent usage of setState
'react/no-set-state': 'off',
// Prevent this from being used in stateless functional components
'react/no-this-in-sfc': 'off',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here — this is a great rule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turned on in f18da27

@@ -92,6 +96,8 @@ module.exports = {

// Enforce boolean attributes notation in JSX
'react/jsx-boolean-value': 'error',
// Enforce or disallow spaces inside of curly braces in JSX attributes and expressions
'react/jsx-child-element-spacing': 'off',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we’d want this rule on as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Prettier already takes care of this for devs, I’m not sure this needs to be turned on

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if Prettier would take care of this? It's more of a clarification mechanism for developers, and in any case, Prettier is not necessarily being used when using this particular set of rules (if it does conflict with Prettier, we can turn it off just for the prettier config)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're right, I was thinking of another rule that had to do with styles and has almost the same name. Turned on in 9978763

@lemonmade
Copy link
Member

All the Jest rules are good but I think we need to disable the lowercase one for now until we can turn it off for describe, as we recommend using the full component/ class name there where appropriate.

@kaelig
Copy link
Contributor Author

kaelig commented Mar 14, 2018

Thank you for the feedback!

Recap of the changes:

  • Allow graphql, css, sass, scss, less, styl file extensions in imports
  • Turn rule jest/valid-expect-in-promise on
  • Turn rule react/no-this-in-sfc on
  • Turn rule react/jsx-child-element-spacing on
  • Turn rule jest/lowercase-name off (for now)

How do we feel about this rule https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/consistent-test-it.md?


This is great! Do we have to do something to have our own rules support he new doc links thing?

Yes we do. I'm opening a new branch for that.

@ismail-syed
Copy link
Contributor

ismail-syed commented Mar 14, 2018

When I wrote jest/lowercase-name , I originally had it to only flag it descriptions. The maintainers suggested enforcing describe and test. jest-community/eslint-plugin-jest#56 (comment).

Glad to see there's an open PR for adding ignore options

@kaelig
Copy link
Contributor Author

kaelig commented Mar 14, 2018

Just published: 20.0.0-beta.4 🚢

@lemonmade react/jsx-child-element-spacing conflicts with prettier:

screenshot 2018-03-14 14 49 27

Replace {'·'} with · (prettier/prettier)


screenshot 2018-03-14 14 49 46

Ambiguous spacing after previous element span


I agree this is a useful rule, any suggestions on how to deal with it?

Edit: found a workaround:

                <span className={styles.HeaderTextShopify}>Shopify</span>{' '}
                Polaris

@lemonmade
Copy link
Member

I still might be misunderstanding the rule, but I don't think they conflict. The biggest overlap is that Prettier might sometimes change code that this rule would flag to not require the explicit space at all (example from the rule):

<div>
  Here is a
  <a>link</a>
</div>

// becomes with Prettier:
<div>Here is a  <a>link</a></div>

// which is acceptable for this rule, which deals only with newline-separate siblings I think

I confirmed that Prettier does not try to correct the case where you make explicitly no space between newline-separate children. I think we are fine to leave this on, and it just kind of works in tandem with the Prettier formatting.

@kaelig
Copy link
Contributor Author

kaelig commented Mar 15, 2018

Thanks, I guess I was a bit confused because you can't add a trailing space into an element (<Foo>foo </Foo> makes ESLint and Prettier conflict) but it's so rarely a thing that I don't think it's an issue.

Let's ship it!

Add docs meta to custom rules
Rewrite rules in imperative tone
@kaelig kaelig merged commit 73e8bcb into master Mar 15, 2018
@kaelig kaelig deleted the eslint-docs branch March 15, 2018 23:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants