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

feat: Add sort-keys rule #76

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

RobertAKARobin
Copy link

@RobertAKARobin RobertAKARobin commented Jan 9, 2025

Prerequisites checklist

What is the purpose of this pull request?

Adds a sort-keys rule for JSON that mimics the functionality of the existing sort-keys for JS.

What changes did you make? (Give an overview)

Added a sort-keys rule and tests.

Related Issues

Fixes #75

Is there anything you'd like reviewers to focus on?

I started by copying over the existing code for JS sort-keys, but it required some big modifications in order to work on JSON. It would be nice if there was an automated way to make sure this sort-keys maintains parity with that sort-keys to keep things consistent across ESLint packages, but JS and JSON are different enough that I'm not sure how it could be done.

* @fileoverview Tests for sort-keys rule. Cribbed from https://github.com/eslint/eslint/blob/main/tests/lib/rules/sort-keys.js. TODO: How to maintain parity with eslint/sort-keys?

Note that I added a TODO for how comments affect line-separated groups

Copy link

linux-foundation-easycla bot commented Jan 9, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@RobertAKARobin RobertAKARobin force-pushed the feat/sort-keys branch 2 times, most recently from 2c210e9 to d651aae Compare January 9, 2025 14:50
package.json Outdated Show resolved Hide resolved
src/rules/sort-keys.js Outdated Show resolved Hide resolved
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Overall this looks good. I left some comments to clean things up.

Also, please add the rule to the rules list in README.md.

package.json Outdated Show resolved Hide resolved
tests/rules/sort-keys.test.js Show resolved Hide resolved
src/rules/sort-keys.js Outdated Show resolved Hide resolved
@RobertAKARobin
Copy link
Author

Think I addressed all feedback. Thanks!

@mdjermanovic mdjermanovic changed the title Add sort-keys rule. Fixes #75 feat: Add sort-keys rule Jan 12, 2025
nzakas
nzakas previously approved these changes Jan 15, 2025
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Just a bit of README cleanup but otherwise LGTM.

README.md Outdated Show resolved Hide resolved
nzakas
nzakas previously approved these changes Jan 16, 2025
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Would like @mdjermanovic to review before merging.

src/rules/sort-keys.js Outdated Show resolved Hide resolved
src/rules/sort-keys.js Outdated Show resolved Hide resolved
src/rules/sort-keys.js Outdated Show resolved Hide resolved
src/rules/sort-keys.js Outdated Show resolved Hide resolved
src/rules/sort-keys.js Outdated Show resolved Hide resolved
`,
language: "json/jsonc",
options: ["asc", { allowLineSeparatedGroups: true }],
languageOptions: { ecmaVersion: 6 },
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
languageOptions: { ecmaVersion: 6 },

Copy link
Author

Choose a reason for hiding this comment

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

Updated 765cbde That was left over from copying from eslint/sort-keys

`,
language: "json/jsonc",
options: ["asc", { allowLineSeparatedGroups: true }],
languageOptions: { ecmaVersion: 6 },
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
languageOptions: { ecmaVersion: 6 },

Copy link
Author

Choose a reason for hiding this comment

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

Updated 765cbde

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

Feat: sort-keys rule
5 participants