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

test: replace and activate json linting #834

Merged

Conversation

MikeMcC399
Copy link
Contributor

Issue

  • The current linting setup does not catch any json errors in the examples.

  • eslint-plugin-json-format is installed, however it is not configured in .eslintrc to be active in terms of the plugin itself, nor the filename extension *.json.

Steps to reproduce

Ubuntu 22.04.4 LTS, Node.js 20.12.2 LTS

Execute

git clone https://github.com/cypress-io/cypress-example-kitchensink
cd cypress-example-kitchensink
npm ci
npm run lint

and confirm that no errors are reported.

Now temporarily delete the end-of-line commas in cypress/fixtures/example.json and save the file.

Execute again

npm run lint

and note that no errors are reported even though the JSON file above is incorrect.

JSON Plugins

  • eslint-plugin-json-format was last published 5 years ago and it seems unlikely that it will be maintained in the future, or that it will offer ESLint 9.x compatibility with flat config file support.

  • eslint-plugin-jsonc is a maintained plugin which provides linting for JSON, JSONC and JSON5 files. It is compatible with ESLint >= 6. It provides legacy and flat config file support.

Options

Correcting the configuration for eslint-plugin-json-format would only be a short-term solution. eslint-plugin-jsonc is used instead.

Change

  1. Uninstall eslint-plugin-json-format
  2. Install eslint-plugin-jsonc
  3. Add plugin:jsonc/recommended-with-json configuration to extends of .eslintrc

@cypress-app-bot
Copy link
Collaborator

@MikeMcC399
Copy link
Contributor Author

Verification

Ubuntu 22.04.4 LTS, Node.js 20.12.2 LTS

Execute

git clone --branch replace/json-linting https://github.com/MikeMcC399/cypress-example-kitchensink --depth 1
cd cypress-example-kitchensink
npm ci
npm run lint

and confirm that no errors are reported.

Now temporarily delete the end-of-line commas in the local copy of cypress/fixtures/example.json and save the file.

Execute again

npm run lint

and note that a JSON error is correctly detected in an error message similar to the following:

$ npm run lint

> cypress-example-kitchensink@0.0.0-development lint
> eslint --fix cypress app/assets/js/scripts.js

.../cypress-example-kitchensink/cypress/fixtures/example.json
  3:3  error  Parsing error: Unexpected token '"email"'

✖ 1 problem (1 error, 0 warnings)

@MikeMcC399

This comment was marked as resolved.

@MikeMcC399 MikeMcC399 marked this pull request as ready for review May 1, 2024 16:54
@jennifer-shehane jennifer-shehane merged commit 27c1fe5 into cypress-io:master May 2, 2024
10 checks passed
@MikeMcC399 MikeMcC399 deleted the replace/json-linting branch May 2, 2024 15:11
@cypress-app-bot
Copy link
Collaborator

🎉 This PR is included in version 2.0.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants