Perfectionist

Getting Started

Before you start, take a moment to support the project by giving us a star on GitHub.

Your support helps the continued development and improvement of this project.

Installation

Okay, let’s get started. You’ll first need to install ESLint:

npm install --save-dev eslint

Next, install eslint-plugin-perfectionist:

npm install --save-dev eslint-plugin-perfectionist

Usage

Add perfectionist to the plugins section of your ESLint configuration. Then configure the rules you want to use under the rules section.

// .eslintrc.js
module.exports = {
plugins: [
'perfectionist',
],
rules: {
'perfectionist/sort-imports': 'error',
},
}

Settings

Many rules have common settings. You can set them in the settings field.

The highest priority is given to the settings of a particular rule. Next comes the settings field and the lowest priority has default values.

In settings you can set the following options:

  • type — The type of sorting. Possible values are 'alphabetical', 'natural', 'line-length' and custom.
  • order — The order of sorting. Possible values are 'asc' and 'desc'.
  • alphabet — The custom alphabet to use when type is custom.
  • ignoreCase — Ignore case when sorting.
  • ignorePattern — Ignore sorting for elements that match the pattern.
  • specialCharacters — Control whether special characters should be kept, trimmed or removed before sorting. Values can be 'keep', 'trim' or 'remove'.
  • locales - The locales of sorting. Values can be a string with a BCP 47 language tag, or an array of such strings. See String.prototype.localeCompare() - locales.
  • partitionByComment — Partition the sorted elements by comments. Values can be true, false or regexp pattern.
  • partitionByNewLine — Partition the sorted elements by new lines. Values can be true or false.

Example:

// .eslintrc.js
module.exports = {
plugins: [
'perfectionist',
],
rules: {
'perfectionist/sort-objects': ['error', {
type: 'alphabetical',
}],
'perfectionist/sort-interfaces': ['error'],
},
settings: {
perfectionist: {
type: 'line-length',
partitionByComment: true,
},
},
}

Table of Contents