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

test(rome_js_analyze): every rule has its folder #4318

Merged
merged 1 commit into from
Mar 27, 2023
Merged

test(rome_js_analyze): every rule has its folder #4318

merged 1 commit into from
Mar 27, 2023

Conversation

Conaclos
Copy link
Contributor

@Conaclos Conaclos commented Mar 22, 2023

Summary

This PR normalizes the folder structure of linter tests: every rule has a dedicated folder.

Moreover, I caught a copy-paste error: correctness/noDuplicateObjectKeys.js.snap has been moved to suspicious/noDuplicateObjectKeys.js.snap. However, the original file was not removed. This kind of error should be easier to catch with the new structure.

I also turn some files into JSONC. This is easier to catch a potential missing diagnostic since the code and the diagnostic are close.

I also updated the CONTRIBUTING file to encourage the use of folder. By the way, we could change the test script to require it...

Test Plan

Documentation

CONTRIBUTING updated.

  • The PR requires documentation
  • I will create a new PR to update the documentation

@netlify
Copy link

netlify bot commented Mar 22, 2023

Deploy Preview for docs-rometools ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b22f6bf
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/642163b3feee81000881a731
😎 Deploy Preview https://deploy-preview-4318--docs-rometools.netlify.app/playground
📱 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.

@github-actions github-actions bot added the A-Linter Area: linter label Mar 22, 2023
@ematipico
Copy link
Contributor

ematipico commented Mar 26, 2023

Assuming that orphan snapshots is just an issue of insta - you can delete any testing assertion and the snapshot won't be deleted - and not of the testing infrastructure, what's this change going to solve/make better for us?

What's the change around JSON? I can't understand the argument around the diagnostics

@Conaclos
Copy link
Contributor Author

Conaclos commented Mar 26, 2023

what's this change going to solve/make better for us?

In my view it makes new contributor entrance easier because there is a single way to start writing tests. Moreover, it makes easier to identify in a tree view where the tests are located since everything is in a folder.

What's the change around JSON? I can't understand the argument around the diagnostics

Baically with a js file you get the following snpshot:

# Input
```js
let x = 1; foo(x)

let x = 1; x++;

for (let i in [1,2,3]) { foo(i); }
```

# Diagnostics
```
invalid.js:1:1 lint/style/useConst  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ! This 'let' declares a variable which is never re-assigned.
  
  > 1 │ let x = 1; foo(x);
      │ ^^^
  
  i 'x' is never re-assigned.
  
  > 1 │ let x = 1; foo(x);
      │     ^

invalid.js:5:6 lint/style/useConst  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ! This 'let' declares a variable which is never re-assigned.
  
  > 3 │ for (let i in [1,2,3]) { foo(i); }
      │      ^^^
  
  i 'i' is never re-assigned.
  
  > 1 │ for (let i in [1,2,3]) { foo(i); }
      │          ^

```

While with jsonc, you get the following snapshot:

# Input
```js
let x = 1; foo(x);
```

# Diagnostics
```
invalid.jsonc:1:1 lint/style/useConst  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ! This 'let' declares a variable which is never re-assigned.
  
  > 1 │ let x = 1; foo(x);
      │ ^^^
  
  i 'x' is never re-assigned.
  
  > 1 │ let x = 1; foo(x);
      │     ^
```

# Input
```js
let x = 1; x++;
```

# Input
```js
for (let i in [1,2,3]) { foo(i); }
```

# Diagnostics
```
invalid.jsonc:1:6 lint/style/useConst  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ! This 'let' declares a variable which is never re-assigned.
  
  > 1 │ for (let i in [1,2,3]) { foo(i); }
      │      ^^^
  
  i 'i' is never re-assigned.
  
  > 1 │ for (let i in [1,2,3]) { foo(i); }
      │          ^
```

It is easier to catch in the second form that an input does not trigger the rule, and thus the test is either in the wrong file (in invalid.jsonc instead of valid.jsonc) or the rule implementation has an issue. This is because the inputs and diagnostics are grouped in the snapshot.

@ematipico
Copy link
Contributor

I think there's something wrong with the code blocks, both have diagnostics coming from a jsonc file.

I would argue that having a JS file is better with IDE experience, because you can see if you write wrong code.
Anyway, this seems to be bikeshedding and I don't want to stop the PR from being merged!

@Conaclos
Copy link
Contributor Author

I think there's something wrong with the code blocks, both have diagnostics coming from a jsonc file.

Fixed. They are "hand-made" examples.

Copy link
Contributor

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Don't we have to change the test runner to make sure that only folders are allowed?

crates/rome_analyze/CONTRIBUTING.md Outdated Show resolved Hide resolved
crates/rome_analyze/CONTRIBUTING.md Outdated Show resolved Hide resolved
@Conaclos Conaclos merged commit e68674c into rome:main Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants