Socket
Socket
Sign inDemoInstall

eslint-plugin-sort-keys-fix

Package Overview
Dependencies
4
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-sort-keys-fix


Version published
Maintainers
1
Install size
1.41 MB
Created

Package description

What is eslint-plugin-sort-keys-fix?

The eslint-plugin-sort-keys-fix package is an ESLint plugin that automatically sorts the keys of objects in your JavaScript code. It helps maintain a consistent key order in objects, which can improve readability and reduce merge conflicts.

What are eslint-plugin-sort-keys-fix's main functionalities?

Sort Object Keys

This feature enforces a rule that automatically sorts the keys of objects in your code. When the rule is set to 'error', ESLint will throw an error if the keys are not sorted, and it will automatically fix the order when possible.

{
  "rules": {
    "sort-keys-fix/sort-keys-fix": "error"
  }
}

Custom Order

This feature allows you to customize the sorting order. In this example, keys are sorted in ascending order, case-sensitive, and without natural sorting. You can adjust these options to fit your project's needs.

{
  "rules": {
    "sort-keys-fix/sort-keys-fix": ["error", "asc", { "caseSensitive": true, "natural": false }]
  }
}

Other packages similar to eslint-plugin-sort-keys-fix

Readme

Source

eslint-plugin-sort-keys-fix

Fork of eslint rule that sorts keys in objects (https://eslint.org/docs/rules/sort-keys) with autofix enabled

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-sort-keys-fix:

$ npm install eslint-plugin-sort-keys-fix --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-sort-keys-fix globally.

Usage

Add sort-keys-fix to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": [
    "sort-keys-fix"
  ]
}

Then add sort-keys-fix rule under the rules section.

{
    "rules": {
        "sort-keys-fix/sort-keys-fix": "warn"
    }
}

Often it makes sense to enable sort-keys-fix only for certain files/directories. For cases like that, use override key of eslint config:

{
  "rules": {
    // ...
  },
  "overrides": [
    {
      "files": ["src/alphabetical.js", "bin/*.js", "lib/*.js"],
      "rules": {
        "sort-keys-fix/sort-keys-fix": "warn"
      }
    }
  ]
}

Rule configuration

For available config options, see official sort-keys reference. All options supported by sort-keys, besides minKeys, are supported by sort-keys-fix.

Keywords

FAQs

Last updated on 02 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc