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: Rule API updates for v9 #471

Merged
merged 9 commits into from Sep 26, 2023
Merged

feat: Rule API updates for v9 #471

merged 9 commits into from Sep 26, 2023

Conversation

nzakas
Copy link
Member

@nzakas nzakas commented Sep 21, 2023

Prerequisites checklist

What is the purpose of this pull request?

What changes did you make? (Give an overview)

Wrote a blog post about the deprecated properties and methods rules need to be aware of.

Related Issues

Is there anything you'd like reviewers to focus on?

Check spelling and grammar please :)

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for hi-eslint ready!

Name Link
🔨 Latest commit e147c69
🔍 Latest deploy log https://app.netlify.com/sites/hi-eslint/deploys/6512ecad1d8f7500086841da
😎 Deploy Preview https://deploy-preview-471--hi-eslint.netlify.app/blog/2023/09/preparing-custom-rules-eslint-v9
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for new-eslint ready!

Name Link
🔨 Latest commit e147c69
🔍 Latest deploy log https://app.netlify.com/sites/new-eslint/deploys/6512ecad8149100008bea75f
😎 Deploy Preview https://deploy-preview-471--new-eslint.netlify.app/blog/2023/09/preparing-custom-rules-eslint-v9
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for es-eslint ready!

Name Link
🔨 Latest commit e147c69
🔍 Latest deploy log https://app.netlify.com/sites/es-eslint/deploys/6512ecadc33f82000871551f
😎 Deploy Preview https://deploy-preview-471--es-eslint.netlify.app/blog/2023/09/preparing-custom-rules-eslint-v9
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for ja-eslint ready!

Name Link
🔨 Latest commit e147c69
🔍 Latest deploy log https://app.netlify.com/sites/ja-eslint/deploys/6512ecafbf904c0008ff3d5a
😎 Deploy Preview https://deploy-preview-471--ja-eslint.netlify.app/blog/2023/09/preparing-custom-rules-eslint-v9
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for de-eslint ready!

Name Link
🔨 Latest commit e147c69
🔍 Latest deploy log https://app.netlify.com/sites/de-eslint/deploys/6512ecaecb9af7000744c518
😎 Deploy Preview https://deploy-preview-471--de-eslint.netlify.app/blog/2023/09/preparing-custom-rules-eslint-v9
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for pt-br-eslint ready!

Name Link
🔨 Latest commit e147c69
🔍 Latest deploy log https://app.netlify.com/sites/pt-br-eslint/deploys/6512ecaeb19e4b0008c27db0
😎 Deploy Preview https://deploy-preview-471--pt-br-eslint.netlify.app/blog/2023/09/preparing-custom-rules-eslint-v9
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for fr-eslint ready!

Name Link
🔨 Latest commit e147c69
🔍 Latest deploy log https://app.netlify.com/sites/fr-eslint/deploys/6512ecadb19e4b0008c27dae
😎 Deploy Preview https://deploy-preview-471--fr-eslint.netlify.app/blog/2023/09/preparing-custom-rules-eslint-v9
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for zh-hans-eslint ready!

Name Link
🔨 Latest commit e147c69
🔍 Latest deploy log https://app.netlify.com/sites/zh-hans-eslint/deploys/6512ecad653113000837a014
😎 Deploy Preview https://deploy-preview-471--zh-hans-eslint.netlify.app/blog/2023/09/preparing-custom-rules-eslint-v9
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

|`context.getSourceLines()`|`sourceCode.getLines()`|
|`context.getAllComments()`|`sourceCode.getAllComments()`|
|`context.getNodeByRangeIndex()`|`sourceCode.getNodeByRangeIndex()`|
|`context.getComments()`|`sourceCode.getComments()`|
Copy link
Member

Choose a reason for hiding this comment

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

sourceCode.getComments() is actually going to be removed in v9: eslint/eslint#14744.

sourceCode.getCommentsBefore(), sourceCode.getCommentsAfter(), and sourceCode.getCommentsInside() should be used instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!


Additionally, the `context.parserOptions` and `context.parserPath` properties are deprecated and will be removed in v9.0.0. There is a new `context.languageOptions` property that allows rules to access similar data as `context.parserOptions`. In general, though, rules should not depend on information either in `context.parserOptions` or `context.languageOptions` to determine how they should behave; this information is primarily for debugging purposes.

The `context.parserPath` property was intended to allow rules to retrieve an instance of the parser that ESLint is using via `require()`. However, the new flat config system does not know the location of the parser module to load, so we are unable to provide this data. Further, because the JavaScript ecosystem is moving to ESM, any value returned from this property will not work with `import()`. This property was added early on in ESLint's life and we generally recommend that rules not try to further parse JavaScript code inside of them.
Copy link
Member

Choose a reason for hiding this comment

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

Shall we mention that context.languageOptions.parser can be used instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I went back and forth on this, but I'll add it. For non-JS languages this won't work, though because the parser (likely) won't be customizable and therefore not appear in languageOptions.

};
```

## `context` properties being removed
Copy link
Member

Choose a reason for hiding this comment

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

In eslint/eslint#13481, removing context.parserPath and context.parserOptions is in Phase 5: Remove eslintrc, which would be in eslint v10, not v9?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call


## `context` properties being removed

Additionally, the `context.parserOptions` and `context.parserPath` properties are deprecated and will be removed in v9.0.0. There is a new `context.languageOptions` property that allows rules to access similar data as `context.parserOptions`. In general, though, rules should not depend on information either in `context.parserOptions` or `context.languageOptions` to determine how they should behave; this information is primarily for debugging purposes.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if using context.languageOptions should generally be discouraged. We're using it in multiple core rules:

https://github.com/search?q=repo%3Aeslint%2Feslint+context.languageOptions&type=code

parserOptions.ecmaVersion was unreliable but languageOptions.ecmaVersion as an option of ESLint itself rather than a parser-specific feature fixes those issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

I still feel like it's a bit of a bad practice as things like ecmaVersion aren't guaranteed to mean anything, especially with so many people using custom parsers.

nzakas and others added 7 commits September 21, 2023 16:52
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
@nzakas
Copy link
Member Author

nzakas commented Sep 25, 2023

I'm planning on merging this tomorrow, so any final comments appreciated.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving this open if anyone else wants to take a look.

Co-authored-by: Amaresh  S M  <amareshsm13@gmail.com>
@nzakas nzakas merged commit 89d1872 into main Sep 26, 2023
14 of 17 checks passed
@nzakas nzakas deleted the deprecated-context-methods branch September 26, 2023 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

None yet

3 participants