Skip to content

Commit db0a55a

Browse files
authored
Add meta property and flat config docs (#155)
1 parent 4c7cb45 commit db0a55a

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

README.md

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,39 @@ npm install --save-dev eslint-plugin-simple-import-sort
6969
7070
## Usage
7171

72-
Add `"simple-import-sort"` to `"plugins"` in your .eslintrc:
73-
74-
```json
75-
{
76-
"plugins": ["simple-import-sort"]
77-
}
78-
```
79-
80-
Then add the rules for sorting imports and exports:
81-
82-
```json
83-
{
84-
"rules": {
85-
"simple-import-sort/imports": "error",
86-
"simple-import-sort/exports": "error"
72+
- [eslintrc]: Add `"simple-import-sort"` to the "plugins" array in your `.eslintrc.*` file, and add the rules for sorting imports and exports. By default ESLint doesn’t parse `import` syntax – the "parserOptions" is an example of how to enable that.
73+
74+
```json
75+
{
76+
"plugins": ["simple-import-sort"],
77+
"rules": {
78+
"simple-import-sort/imports": "error",
79+
"simple-import-sort/exports": "error"
80+
},
81+
"parserOptions": {
82+
"sourceType": "module",
83+
"ecmaVersion": "latest"
84+
}
8785
}
88-
}
89-
```
86+
```
87+
88+
- [eslint.config.js (flat config)]: Import eslint-plugin-simple-import-sort, put it in the `plugins` object, and add the rules for sorting imports and exports. With flat config, `import` syntax is enabled by default.
89+
90+
```js
91+
import simpleImportSort from "eslint-plugin-simple-import-sort";
92+
93+
export default [
94+
{
95+
plugins: {
96+
"simple-import-sort": simpleImportSort,
97+
},
98+
rules: {
99+
"simple-import-sort/imports": "error",
100+
"simple-import-sort/exports": "error",
101+
},
102+
},
103+
];
104+
```
90105

91106
Make sure _not_ to use other sorting rules at the same time:
92107

@@ -104,9 +119,9 @@ It is recommended to also set up [Prettier], to help formatting your imports (an
104119
```json
105120
{
106121
"parserOptions": {
107-
"sourceType": "module"
122+
"sourceType": "module",
123+
"ecmaVersion": "latest"
108124
},
109-
"env": { "es6": true },
110125
"plugins": ["simple-import-sort", "import"],
111126
"rules": {
112127
"simple-import-sort/imports": "error",
@@ -118,7 +133,7 @@ It is recommended to also set up [Prettier], to help formatting your imports (an
118133
}
119134
```
120135

121-
- `"sourceType": "module"` is needed so ESLint doesn’t report `import` and `export` as syntax errors.
136+
- `"sourceType": "module"` and `"ecmaVersion": "latest"` are needed so ESLint doesn’t report `import` and `export` as syntax errors.
122137
- `simple-import-sort/imports` and `simple-import-sort/exports` are turned on for all files.
123138
- [import/first] makes sure all imports are at the top of the file. (autofixable)
124139
- [import/newline-after-import] makes sure there’s a newline after the imports. (autofixable)
@@ -706,7 +721,9 @@ For example, here’s the default value but changed to a single inner array:
706721
[comment-handling]: #comment-and-whitespace-handling
707722
[custom grouping]: #custom-grouping
708723
[eslint-getting-started]: https://eslint.org/docs/user-guide/getting-started
724+
[eslint.config.js (flat config)]: https://eslint.org/docs/latest/use/configure/configuration-files-new
709725
[eslint]: https://eslint.org/
726+
[eslintrc]: https://eslint.org/docs/latest/use/configure/configuration-files
710727
[example-ignore]: ./examples/ignore.js
711728
[examples]: ./examples/.eslintrc.js
712729
[exports]: #exports

build.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const fs = require("fs");
44
const path = require("path");
5+
const PACKAGE = require("./package-real.json");
56

67
const DIR = __dirname;
78
const SRC = "src";
@@ -17,9 +18,11 @@ const FILES_TO_COPY = [
1718
src: "README.md",
1819
transform: (content) => content.replace(/<!--[^]*$/, READ_MORE),
1920
},
20-
...fs
21-
.readdirSync(SRC)
22-
.map((file) => ({ src: path.join(SRC, file), dest: file })),
21+
...fs.readdirSync(SRC).map((file) => ({
22+
src: path.join(SRC, file),
23+
dest: file,
24+
transform: (content) => content.replace(/%VERSION%/g, PACKAGE.version),
25+
})),
2326
];
2427

2528
fs.rmSync(BUILD, { recursive: true, force: true });

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const importsRule = require("./imports");
44
const exportsRule = require("./exports");
55

66
module.exports = {
7+
meta: {
8+
name: "eslint-plugin-simple-import-sort",
9+
version: "%VERSION%",
10+
},
711
rules: {
812
imports: importsRule,
913
exports: exportsRule,

0 commit comments

Comments
 (0)