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

feat(rome_js_analyze): lint/correctness/noDupeKeys #3562

Merged
merged 22 commits into from
Nov 14, 2022

Conversation

jeysal
Copy link
Contributor

@jeysal jeysal commented Nov 4, 2022

Summary

Resolves #3364

Note that I've stopped short of feature parity with ESLint because the PR already got pretty big. The rule can be extended later. I can open a follow up to #3364 when this is merged.
The cases that ESLint covers but this doesn't can be seen in the test file - number-keyed properties and computed-string-literal-keyed properties.

Test Plan

Used standard lint test infrastructure, had to extend slightly for the suggested fix action

@netlify
Copy link

netlify bot commented Nov 4, 2022

Deploy Preview for docs-rometools ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 1b0f6fa
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/63725973b6a5f30008dac3ce
😎 Deploy Preview https://deploy-preview-3562--docs-rometools.netlify.app
📱 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 settings.

Copy link
Contributor Author

@jeysal jeysal left a comment

Choose a reason for hiding this comment

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

There are some things to figure out still, but overall it turned out pretty clean I'd say.
Not sure yet if I'll continue on the weekend or later.
I hit some infra issues that would probably be quickest solved with some help from someone who's already had to deal with similar things, see my comments.

for member in node
.members()
.into_iter()
// Note that we iterate from last to first property, so that we highlight properties being overwritten as problems and not those that take effect.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be a bit of a hot take, and ESLint does it the other way.
But I think it's the right way, esp. considering the fix suggestion.

crates/rome_diagnostics_categories/src/categories.rs Outdated Show resolved Hide resolved
* upstream/main:
  fix(ci): fix the release workflows for the stable release (rome#3583)
  Fix logo container margin
  Fix mobile docs regressions
  perf: End-to-end Linter and Formatter benchmarks (rome#3570)
  doc: VS Code extension (rome#3579)
  refactor(rome_cli): refactor the threading of parallel traversal to increase occupancy (rome#3577)
  [docs] Add navigation dropdown for docs (rome#3578)
  doc(rome_cli): Document `--files-max-size` option
  perf(rome_js_semantic): Use FX Hash function (rome#3565)
  fix(rome_js_analyzer): `noInvalidConstructorSuper` false positive for class expressions (rome#3561)
  Clean up mobile navigation
  doc(website): Run `cargo lintdoc` (rome#3567)
  doc: Fix install command
  Fix mobile code blocks
  Fix dark mode logo
  Update links
  Implement new website (rome#3556)
* upstream/main:
  fix(rome_js_analyze): improve the logic of jsx_reference_identifier_is_fragment (rome#3592)
  doc: Fix configuration example
  Add crossorigin header
  Improve font performance
  release: 10.0.0 (rome#3526)
  fix(docs): use the standard picture element to display the logo (rome#3585)
…operty definition

even in the case of a value being overwritten by a getter and a setter,
only highlight the latter of those two
/// Asserts the removal worked.
pub fn assert_remove_ok(before: &str, expected: &str) {
pub fn assert_remove_identifier_a_ok<Anc: AstNode<Language = JsLanguage> + Debug>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to generalize this test util a bit so that it can look for any identifier token and then you tell it how much around the token you'd like to remove by giving it an ancestor type to look for

@@ -113,8 +146,7 @@ pub fn ok_find_attributes_by_name() {
let list = r
.syntax()
.descendants()
.filter_map(rome_js_syntax::JsxAttributeList::cast)
.next()
.find_map(rome_js_syntax::JsxAttributeList::cast)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

autofix 😅


// valid for now

// ESLint already catches properties keyed with different-formatted number literals, we haven't implemented it yet.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR has grown pretty big already so I'll leave this for a future extension to the rule 😅

@@ -75,14 +75,15 @@ define_dategories! {


// nursery
"lint/nursery/useFlatMap": "https://docs.rome.tools/lint/rules/useFlatMap",
"lint/nursery/noBannedTypes":"https://docs.rome.tools/lint/rules/noBannedTypes",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

went ahead and pressed sort on these as there was no apparent order to them

@jeysal jeysal marked this pull request as ready for review November 8, 2022 18:04
@jeysal jeysal requested a review from a team November 8, 2022 18:04
@jeysal
Copy link
Contributor Author

jeysal commented Nov 8, 2022

This PR is ready for review now! :)
I left some comments with explanations and some with minor implementation questions, but overall I'm pretty happy, esp. with the diagnostic as well.
As noted in the PR description, this rule is not at feature parity with the ESLint one yet. It was already getting pretty big, so this can be shipped and then extended later.

@MichaReiser MichaReiser added this to the 11.0.0 milestone Nov 9, 2022
Copy link
Contributor

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Well done. I have a few small nits, and we must wait to merge until the 10.0.1 patch release is out of the door.

crates/rome_js_analyze/src/utils/batch.rs Outdated Show resolved Hide resolved
jeysal and others added 5 commits November 9, 2022 16:12
* upstream/main:
  fix(rome_js_analyze): Verify method name of React API calls (rome#3619)
  benchmark: Add pprettier and dprint to benchmark (rome#3597)
  feat(vscode): display the version of the language server in the status bar (rome#3616)
  fix(rome_cli): correctly account for diff diagnostics in the printed diagnostics count (rome#3595)
  fix(rome_cli): Respect formatter/linter `enabled` from configuration (rome#3591)
  Remove dead styles
  [website] Add scroll-padding-top
Co-authored-by: Micha Reiser <micha@reiser.io>
* origin/no-dupe-keys:
  Update crates/rome_js_analyze/src/analyzers/nursery/no_dupe_keys.rs
* upstream/main:
  fix(npm/js-api): Import type from @rometools/backend-jsonrpc (rome#3647)
  doc(npm/js-api): Add experimental warning to README
  fix(npm/js-api): Lazy load backend implementations (rome#3652)
  feat(rome_lsp): stop the daemon after the last client disconnects (rome#3643)
  fix(npm/js_api): Ensure JS API build contains `dist` folder (rome#3648)
  fix(rome_cli): ensures the service only connects to compatible versions (rome#3642)
  feat(playground): add settings button and group IR (rome#3559)
  release: v10.0.1 (rome#3649)
  fix(rome_js_analyze): False positives for interactive elements in `useKeyWithClickEvents` (rome#3644)
  fix(rome_js_semantic): support for object and array bindings when exporting (rome#3620)
  doc(editors): Clarify Rome discovery (rome#3639)
  fix(rome_js_analyze): improve the detection of `ReactDOM.render` calls in `noRenderReturnValue` (rome#3626)
  chore(npm): add license (rome#3629)
  Add rustdocs index
  Add environment
  Change rust docs to use Netlify
  fix(rome_js_analyze): useValidAnchor considering all possible expressions (rome#3599)
  fix(rome_js_formatter): Trailing comma inside import rome#3600 (rome#3624)
@jeysal jeysal requested a review from a team November 10, 2022 21:33
@jeysal
Copy link
Contributor Author

jeysal commented Nov 10, 2022

All comments addressed with changes or explanations why they were left unchanged.
Also merged in main.
Should be ready to go once 11.0.0 merges are starting!
Ping me if it becomes out of date with main or so.

* upstream/main:
  fix(website): fix grammar mistake (rome#3666)
  doc(website): Use `pnpm rome` and `yarn rome` instead of longer versions
  docs: change indent-style from tabs to tab (rome#3657)
  Revert "[website] Port docs to astro" (rome#3662)
  [website] Port docs to astro (rome#3659)
@jeysal
Copy link
Contributor Author

jeysal commented Nov 11, 2022

@MichaReiser I refactored quite a lot and should have addressed your concerns about too wide typings and about blurry naming conventions.

Member definitions now clearly use the existing terminology that you mentioned.
Defined properties now make it clear that they refer to property descriptors that we think will make it into the final object.

I also used more impls and traits to perhaps make the core algorithm of the rule itself easier to read.
It's overall a couple tens of lines plus in the diff, but perhaps you'll find it clearer.
Maybe the type narrowing will be of benefit in future extensions to the rule.

Copy link
Contributor

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

We're good to go after you resolved the merge conflicts.

* upstream/main: (45 commits)
  website(docs): set `color-scheme` on the root element (rome#3721)
  feat(rome_analyze): add a warning for unused suppression comments (rome#3718)
  feat(rome_js_analyze): Implement prefer-numeric-literals lint (rome#3558)
  feat(rome_js_formatter): jestEach template literals rome#3308 (rome#3582)
  doc(website): Add context about Romes philosophy (rome#3714)
  fix(rome_js_formatter): Single-line comment below a JSX prop triggers… (rome#3641)
  test(rome_js_formatter): update prettier tests (rome#3684)
  fix(rome_js_parser): improve await handling in non-async context (rome#3573)
  fix(rome_js_parser): improve yield parsing in non generator function (rome#3622)
  More playground polish
  Fix backgrounds
  Fix height
  Align docs.rome.tools with rome.tools
  Reenable compression
  Add missing width
  website(docs): More playground IDE features (rome#3711)
  fix(rome_js_formatter): new expression attribute (rome#3686)
  docs(website): added checkbox to toggle linter in playground (rome#3699)
  website(docs): More website tweaks (rome#3707)
  website(docs): Add default layout property (rome#3705)
  ...
@jeysal
Copy link
Contributor Author

jeysal commented Nov 14, 2022

@MichaReiser merged in main!

@MichaReiser MichaReiser added the A-Linter Area: linter label Nov 14, 2022
@MichaReiser MichaReiser merged commit 7082c83 into rome:main Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

no-dupe-keys
4 participants