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

Added no-unsafe rule #1831

Merged
merged 5 commits into from Jun 21, 2018
Merged

Conversation

sergei-startsev
Copy link
Contributor

@sergei-startsev sergei-startsev commented Jun 17, 2018

Added no-unsafe rule to address the corresponding issue #1830. See discussion details #1750 (comment).

Fixes #1830

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

This rule should only be active when the React pragma version is in a range that supports the unsafe methods - 16.3 or 16.4+, i think?


context.report({
node: node,
message: `Do not use ${method}`
Copy link
Member

Choose a reason for hiding this comment

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

the message should explain why, and link to more info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added details

`,
errors: [
{
message: 'Do not use UNSAFE_componentWillMount'
Copy link
Member

Choose a reason for hiding this comment

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

these tests should include position information, so that we can test that part 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.

Added a few more tests and position details for invalid cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that added position details causes issues in eslint 3, see TEST=true ESLINT=3 failed travis builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted tests to support ESLint 3

@sergei-startsev
Copy link
Contributor Author

The rule is applicable for 16.3.0+ only now, good point.

@@ -44,7 +45,8 @@ module.exports = {
*/
function isUnsafe(method) {
const unsafeMethods = getUnsafeMethods();
return unsafeMethods.indexOf(method) !== -1;
const isApplicable = versionUtil.testReactVersion(context, '16.3.0');
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a check we could do earlier, and prevent even returning any visitors in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added early termination for the rule.

index.js Outdated
@@ -139,6 +140,7 @@ module.exports = {
'react/no-string-refs': 2,
'react/no-unescaped-entities': 2,
'react/no-unknown-property': 2,
'react/no-unsafe': 2,
Copy link
Member

Choose a reason for hiding this comment

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

enabling new rules in an exported config is a semver-major change; please set this to 0 for now.

docs: {
description: 'Prevent usage of UNSAFE_ methods',
category: 'Best Practices',
recommended: true,
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@sergei-startsev
Copy link
Contributor Author

Excluded the rule from the recommended for now. Would we like to track it somehow to turn on it in the next major release?

@EvHaus
Copy link
Collaborator

EvHaus commented Jun 21, 2018

Why not build this logic into the existing no-deprecated rule as opposed to creating a new dedicated rule?

@ljharb
Copy link
Member

ljharb commented Jun 21, 2018

I don't consider them deprecated yet, because there's not a replacement for all of their use cases.

@sergei-startsev
Copy link
Contributor Author

@EvHaus UNSAFE_ methods aren't deprecated, so no-deprecated rule isn't the right place for that. See discussion details #1750 (comment).

Copy link
Collaborator

@EvHaus EvHaus left a comment

Choose a reason for hiding this comment

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

LGTM

@ljharb ljharb merged commit 7869530 into jsx-eslint:master Jun 21, 2018
calebeby pushed a commit to Pigmice2733/scouting-frontend that referenced this pull request Jun 30, 2018
This Pull Request updates dependency [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) from `v7.9.1` to `v7.10.0`



<details>
<summary>Release Notes</summary>

### [`v7.10.0`](https://github.com/yannickcr/eslint-plugin-react/blob/master/CHANGELOG.md#&#8203;7100---2018-06-24)
[Compare Source](jsx-eslint/eslint-plugin-react@v7.9.1...v7.10.0)
##### Added
* Allow eslint ^5 ([#&#8203;1843][] @&#8203;papandreou, @&#8203;ljharb)
* [`no-unsafe`][] rule ([#&#8203;1831][], [#&#8203;1830][] @&#8203;sergei-startsev)
* [`no-will-update-set-state`][]: Account for `UNSAFE_` methods ([#&#8203;1845][], [#&#8203;1844][] @&#8203;alexzherdev)
##### Fixed
* [`no-typos`][]: Fix static propTypes handling ([#&#8203;1827][], [#&#8203;1677][] @&#8203;alexzherdev)
* [`destructuring-assignment`][]: Allow LHS ([#&#8203;1825][], [#&#8203;1728][] @&#8203;alexzherdev)
* [`no-unused-prop-types`][]: Fix crash when encountering mixed union and intersection flow types ([#&#8203;1806][] @&#8203;yannickcr)
##### Changed
* Typo fixes in [`jsx-no-target-blank`][] ([#&#8203;1805][] @&#8203;ferhatelmas))

[#&#8203;1845]: `jsx-eslint/eslint-plugin-react#1845
[#&#8203;1844]: `jsx-eslint/eslint-plugin-react#1844
[#&#8203;1843]: `jsx-eslint/eslint-plugin-react#1843
[#&#8203;1831]: `jsx-eslint/eslint-plugin-react#1831
[#&#8203;1830]: `jsx-eslint/eslint-plugin-react#1830
[#&#8203;1827]: `jsx-eslint/eslint-plugin-react#1827
[#&#8203;1825]: `jsx-eslint/eslint-plugin-react#1825
[#&#8203;1806]: `jsx-eslint/eslint-plugin-react#1806
[#&#8203;1805]: `jsx-eslint/eslint-plugin-react#1805
[#&#8203;1728]: `jsx-eslint/eslint-plugin-react#1728
[#&#8203;1677]: `jsx-eslint/eslint-plugin-react#1677

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

3 participants