Skip to content

chore: add new eslint-plugin with rule no-optional-chaining locally#3233

Merged
thegreatercurve merged 3 commits intofacebook:mainfrom
shanpriyan:no-optional-chain
Oct 24, 2022
Merged

chore: add new eslint-plugin with rule no-optional-chaining locally#3233
thegreatercurve merged 3 commits intofacebook:mainfrom
shanpriyan:no-optional-chain

Conversation

@shanpriyan
Copy link
Copy Markdown
Contributor

Resolves #3074

  1. Created a new eslint-plugin inside the project directory and added a new rule (no-optional-chaining) in it.
  2. Added the plugin in .eslintrc.js to detect the usage of optional chaining
  3. Added the locally created eslint-plugin-lexical to package.json

Rule reference: https://github.com/mysticatea/eslint-plugin-es/blob/master/lib/rules/no-optional-chaining.js

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 20, 2022
@vercel
Copy link
Copy Markdown

vercel bot commented Oct 20, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
lexical ✅ Ready (Inspect) Visit Preview Oct 24, 2022 at 3:03PM (UTC)
lexical-playground ✅ Ready (Inspect) Visit Preview Oct 24, 2022 at 3:03PM (UTC)

@shanpriyan
Copy link
Copy Markdown
Contributor Author

Run yarn lint or npm run lint to lint all files

image
image

@shanpriyan
Copy link
Copy Markdown
Contributor Author

shanpriyan commented Oct 20, 2022

Detection after usage of optional chaining

image

@acywatson
Copy link
Copy Markdown
Contributor

Pretty sweet! Let's ignore test files and the playground, I guess

@acywatson
Copy link
Copy Markdown
Contributor

Looks like we also need to ignore lexical-devtools

@shanpriyan
Copy link
Copy Markdown
Contributor Author

Looks like we also need to ignore lexical-devtools

Done 🚀

@abelsj60
Copy link
Copy Markdown
Contributor

abelsj60 commented Dec 5, 2022

@shanpriyan Hi. I'm having some kind of problem with this eslint rule today.

I've just synced my Lexical fork so I can update my local copy. However, I can't complete the commit with all the changes because ESLint is causing Husky to die on this plugin.

Specifically:

  1. Husky reports:
ESLint couldn't find the plugin "eslint-plugin-lexical".

(Despite this, I do see all the code you added to Lexical via this PR in my local copy.)
  1. Then ESLint says:
ESLint: 7.32.0

ESLint couldn't find the plugin "eslint-plugin-lexical".

(The package "eslint-plugin-lexical" was not found when loaded as a Node module from the directory "/Users/james/Desktop/code/lexical".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

    npm install eslint-plugin-lexical@latest --save-dev
...
  1. Finally, when taking ESLint's advice to do a npm install ..., I get the following error:
npm ERR! Cannot convert undefined or null to object

Do you have any advice on how to fix this? Is it possible that you added a file system reference to your "npm registry list", a la https://stackoverflow.com/a/41200925 ? If so, what would I need to add?

I can't even seem to remove the rule, as, each time I do, Husky seems to "magically" reinsert it.

I'm definitely missing something here. Any thoughts that could help?

@abelsj60
Copy link
Copy Markdown
Contributor

abelsj60 commented Dec 5, 2022

@shanpriyan Hi. I'm having some kind of problem with this eslint rule today.

...

Ha! I asked for help in the Eslint Discord and the recommendation seems to have worked right quick:

npm link ./eslint-plugin

Looks like this solves the problem. I'm cautiously optimistic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an eslint rule to prevent optional chaining

5 participants