eslint-plugin-indent-empty-lines 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -3
- package/dist/configs/index.cjs +7 -0
- package/dist/configs/index.js +8 -0
- package/dist/configs/index.js.map +1 -0
- package/dist/configs/recommended.cjs +10 -0
- package/dist/configs/recommended.js +11 -0
- package/dist/configs/recommended.js.map +1 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +86 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/package.cjs +18 -0
- package/dist/package.js +7 -0
- package/dist/package.js.map +1 -0
- package/dist/plugin.cjs +14 -0
- package/dist/plugin.js +15 -0
- package/dist/plugin.js.map +1 -0
- package/dist/rules/indent-empty-lines.cjs +60 -0
- package/dist/rules/indent-empty-lines.js +60 -0
- package/dist/rules/indent-empty-lines.js.map +1 -0
- package/package.json +31 -14
- package/lib/index.js +0 -7
- package/lib/rules/indent-empty-lines.js +0 -74
package/README.md
CHANGED
|
@@ -19,7 +19,30 @@ $ npm install --save-dev eslint-plugin-indent-empty-lines
|
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
### Config - Flat (`eslint.config.js`)
|
|
23
|
+
|
|
24
|
+
Extend `indentEmptyLinesPlugin.configs.recommended` to load the plugin with for default config.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import indentEmptyLinesPlugin from 'eslint-plugin-indent-empty-lines';
|
|
28
|
+
import js from '@eslint/js';
|
|
29
|
+
|
|
30
|
+
export default [
|
|
31
|
+
js.configs.recommended,
|
|
32
|
+
indentEmptyLinesPlugin.configs.recommended,
|
|
33
|
+
{
|
|
34
|
+
rules: {
|
|
35
|
+
"indent-empty-lines/indent-empty-lines": ["warn", 2] // Use to configure the rule
|
|
36
|
+
// ...
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Config - Legacy (`.eslintrc`)
|
|
44
|
+
|
|
45
|
+
Add `indent-empty-lines` to the plugins section of the `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
|
|
23
46
|
|
|
24
47
|
```json
|
|
25
48
|
{
|
|
@@ -29,13 +52,12 @@ Add `indent-empty-lines` to the plugins section of your `.eslintrc` configuratio
|
|
|
29
52
|
}
|
|
30
53
|
```
|
|
31
54
|
|
|
32
|
-
|
|
33
55
|
Then configure the rules you want to use under the rules section.
|
|
34
56
|
|
|
35
57
|
```json
|
|
36
58
|
{
|
|
37
59
|
"rules": {
|
|
38
|
-
"indent-empty-lines/indent-empty-lines": "warn"
|
|
60
|
+
"indent-empty-lines/indent-empty-lines": ["warn", 2]
|
|
39
61
|
}
|
|
40
62
|
}
|
|
41
63
|
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_configs_recommended = require('./recommended.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/configs/index.ts
|
|
4
|
+
var configs_default = { recommended: require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_configs_recommended.recommended_default };
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.configs_default = configs_default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/configs/index.ts"],"sourcesContent":["import recommended from \"./recommended\";\n\nexport default {\n recommended,\n};\n"],"mappings":";;;AAEA,sBAAe,EACb,iCACD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_plugin = require('../plugin.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/configs/recommended.ts
|
|
4
|
+
var recommended_default = {
|
|
5
|
+
plugins: { "indent-empty-lines": require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_plugin.plugin_default },
|
|
6
|
+
rules: { "indent-empty-lines/indent-empty-lines": ["warn", 2] }
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.recommended_default = recommended_default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { plugin_default } from "../plugin.js";
|
|
2
|
+
|
|
3
|
+
//#region src/configs/recommended.ts
|
|
4
|
+
var recommended_default = {
|
|
5
|
+
plugins: { "indent-empty-lines": plugin_default },
|
|
6
|
+
rules: { "indent-empty-lines/indent-empty-lines": ["warn", 2] }
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { recommended_default };
|
|
11
|
+
//# sourceMappingURL=recommended.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recommended.js","names":["plugin"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["import type { ConfigObject } from \"@eslint/core\";\nimport plugin from \"../plugin.ts\";\n\nexport default {\n plugins: {\n \"indent-empty-lines\": plugin,\n },\n rules: {\n \"indent-empty-lines/indent-empty-lines\": [\"warn\", 2],\n },\n} satisfies ConfigObject;\n"],"mappings":";;;AAGA,0BAAe;CACb,SAAS,EACP,sBAAsBA,eACvB;CACD,OAAO,EACL,yCAAyC,CAAC,QAAQ,CAAE,EACrD;AACF"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_plugin = require('./plugin.cjs');
|
|
2
|
+
const require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_configs_index = require('./configs/index.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
var src_default = Object.assign(require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_plugin.plugin_default, { configs: require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_configs_index.configs_default });
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
module.exports = src_default;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as eslint0 from "eslint";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare const _default: {
|
|
5
|
+
meta: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
};
|
|
9
|
+
rules: {
|
|
10
|
+
"indent-empty-lines": {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "layout";
|
|
13
|
+
docs: {
|
|
14
|
+
description: string;
|
|
15
|
+
url: string;
|
|
16
|
+
};
|
|
17
|
+
fixable: "whitespace";
|
|
18
|
+
schema: {
|
|
19
|
+
oneOf: ({
|
|
20
|
+
enum: string[];
|
|
21
|
+
type?: undefined;
|
|
22
|
+
minimum?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
type: "integer";
|
|
25
|
+
minimum: number;
|
|
26
|
+
enum?: undefined;
|
|
27
|
+
})[];
|
|
28
|
+
}[];
|
|
29
|
+
defaultOptions: number[];
|
|
30
|
+
};
|
|
31
|
+
create(context: eslint0.Rule.RuleContext): {
|
|
32
|
+
Program: (node: eslint0.AST.Program | (eslint0.AST.Program & {
|
|
33
|
+
parent: null;
|
|
34
|
+
})) => void;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
} & {
|
|
39
|
+
configs: {
|
|
40
|
+
recommended: {
|
|
41
|
+
plugins: {
|
|
42
|
+
"indent-empty-lines": {
|
|
43
|
+
meta: {
|
|
44
|
+
name: string;
|
|
45
|
+
version: string;
|
|
46
|
+
};
|
|
47
|
+
rules: {
|
|
48
|
+
"indent-empty-lines": {
|
|
49
|
+
meta: {
|
|
50
|
+
type: "layout";
|
|
51
|
+
docs: {
|
|
52
|
+
description: string;
|
|
53
|
+
url: string;
|
|
54
|
+
};
|
|
55
|
+
fixable: "whitespace";
|
|
56
|
+
schema: {
|
|
57
|
+
oneOf: ({
|
|
58
|
+
enum: string[];
|
|
59
|
+
type?: undefined;
|
|
60
|
+
minimum?: undefined;
|
|
61
|
+
} | {
|
|
62
|
+
type: "integer";
|
|
63
|
+
minimum: number;
|
|
64
|
+
enum?: undefined;
|
|
65
|
+
})[];
|
|
66
|
+
}[];
|
|
67
|
+
defaultOptions: number[];
|
|
68
|
+
};
|
|
69
|
+
create(context: eslint0.Rule.RuleContext): {
|
|
70
|
+
Program: (node: eslint0.AST.Program | (eslint0.AST.Program & {
|
|
71
|
+
parent: null;
|
|
72
|
+
})) => void;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
rules: {
|
|
79
|
+
"indent-empty-lines/indent-empty-lines": ["warn", number];
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { _default as default };
|
|
86
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as eslint0 from "eslint";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare const _default: {
|
|
5
|
+
meta: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
};
|
|
9
|
+
rules: {
|
|
10
|
+
"indent-empty-lines": {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "layout";
|
|
13
|
+
docs: {
|
|
14
|
+
description: string;
|
|
15
|
+
url: string;
|
|
16
|
+
};
|
|
17
|
+
fixable: "whitespace";
|
|
18
|
+
schema: {
|
|
19
|
+
oneOf: ({
|
|
20
|
+
enum: string[];
|
|
21
|
+
type?: undefined;
|
|
22
|
+
minimum?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
type: "integer";
|
|
25
|
+
minimum: number;
|
|
26
|
+
enum?: undefined;
|
|
27
|
+
})[];
|
|
28
|
+
}[];
|
|
29
|
+
defaultOptions: number[];
|
|
30
|
+
};
|
|
31
|
+
create(context: eslint0.Rule.RuleContext): {
|
|
32
|
+
Program: (node: eslint0.AST.Program | (eslint0.AST.Program & {
|
|
33
|
+
parent: null;
|
|
34
|
+
})) => void;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
} & {
|
|
39
|
+
configs: {
|
|
40
|
+
recommended: {
|
|
41
|
+
plugins: {
|
|
42
|
+
"indent-empty-lines": {
|
|
43
|
+
meta: {
|
|
44
|
+
name: string;
|
|
45
|
+
version: string;
|
|
46
|
+
};
|
|
47
|
+
rules: {
|
|
48
|
+
"indent-empty-lines": {
|
|
49
|
+
meta: {
|
|
50
|
+
type: "layout";
|
|
51
|
+
docs: {
|
|
52
|
+
description: string;
|
|
53
|
+
url: string;
|
|
54
|
+
};
|
|
55
|
+
fixable: "whitespace";
|
|
56
|
+
schema: {
|
|
57
|
+
oneOf: ({
|
|
58
|
+
enum: string[];
|
|
59
|
+
type?: undefined;
|
|
60
|
+
minimum?: undefined;
|
|
61
|
+
} | {
|
|
62
|
+
type: "integer";
|
|
63
|
+
minimum: number;
|
|
64
|
+
enum?: undefined;
|
|
65
|
+
})[];
|
|
66
|
+
}[];
|
|
67
|
+
defaultOptions: number[];
|
|
68
|
+
};
|
|
69
|
+
create(context: eslint0.Rule.RuleContext): {
|
|
70
|
+
Program: (node: eslint0.AST.Program | (eslint0.AST.Program & {
|
|
71
|
+
parent: null;
|
|
72
|
+
})) => void;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
rules: {
|
|
79
|
+
"indent-empty-lines/indent-empty-lines": ["warn", number];
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { _default as default };
|
|
86
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { plugin_default } from "./plugin.js";
|
|
2
|
+
import { configs_default } from "./configs/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
var src_default = Object.assign(plugin_default, { configs: configs_default });
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { src_default as default };
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["plugin"],"sources":["../src/index.ts"],"sourcesContent":["import configs from './configs'\nimport plugin from './plugin'\n\nexport default Object.assign(plugin, { configs });\n"],"mappings":";;;;AAGA,kBAAe,OAAO,OAAOA,gBAAQ,EAAE,yBAAS,EAAC"}
|
package/dist/package.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
//#region package.json
|
|
3
|
+
var name = "eslint-plugin-indent-empty-lines";
|
|
4
|
+
var version = "1.0.2";
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
Object.defineProperty(exports, 'name', {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return name;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, 'version', {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return version;
|
|
17
|
+
}
|
|
18
|
+
});
|
package/dist/package.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"eslint-plugin-indent-empty-lines\",\n \"version\": \"1.0.2\",\n \"description\": \"Enforce indention on empty lines\",\n \"author\": \"Fun Maker <funmaker95@gmail.com>\",\n \"license\": \"MIT\",\n \"homepage\": \"https://github.com/funmaker/eslint-plugin-indent-empty-lines#readme\",\n \"type\": \"module\",\n \"main\": \"dist/index.js\",\n \"exports\": {\n \"import\": \"./index.mjs\",\n \"require\": \"./index.js\"\n },\n \"scripts\": {\n \"build\": \"tsdown\",\n \"lint\": \"eslint\",\n \"lint-fix\": \"eslint --fix\",\n \"test\": \"mocha 'tests/**/*.ts'\"\n },\n \"engines\": {\n \"node\": \">=20.0.0\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/funmaker/eslint-plugin-indent-empty-lines.git\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/funmaker/eslint-plugin-indent-empty-lines/issues\"\n },\n \"devDependencies\": {\n \"@eslint/compat\": \"^1.4.1\",\n \"@types/mocha\": \"^10.0.10\",\n \"@types/node\": \"^25.0.10\",\n \"@typescript-eslint/eslint-plugin\": \"^8.53.1\",\n \"@typescript-eslint/parser\": \"^8.53.1\",\n \"mocha\": \"^11.7.5\",\n \"tsdown\": \"^0.12.9\",\n \"tsx\": \"^4.21.0\",\n \"typescript\": \"^5.9.3\"\n },\n \"peerDependencies\": {\n \"eslint\": \">=9.0.0\"\n },\n \"files\": [\n \"dist/**/*\"\n ],\n \"keywords\": [\n \"eslint\",\n \"eslintplugin\",\n \"eslint-plugin\"\n ]\n}\n"],"mappings":";WACU;cACG"}
|
package/dist/plugin.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_package = require('./package.cjs');
|
|
2
|
+
const require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_rules_indent_empty_lines = require('./rules/indent-empty-lines.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/plugin.ts
|
|
5
|
+
var plugin_default = {
|
|
6
|
+
meta: {
|
|
7
|
+
name: require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_package.name,
|
|
8
|
+
version: require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_package.version
|
|
9
|
+
},
|
|
10
|
+
rules: { "indent-empty-lines": require__home_funmaker_sync_programming_js_eslint_plugin_indent_empty_lines_src_rules_indent_empty_lines.indent_empty_lines_default }
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.plugin_default = plugin_default;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { name, version } from "./package.js";
|
|
2
|
+
import { indent_empty_lines_default } from "./rules/indent-empty-lines.js";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin.ts
|
|
5
|
+
var plugin_default = {
|
|
6
|
+
meta: {
|
|
7
|
+
name,
|
|
8
|
+
version
|
|
9
|
+
},
|
|
10
|
+
rules: { "indent-empty-lines": indent_empty_lines_default }
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { plugin_default };
|
|
15
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","names":["indentEmptyLines"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { Plugin } from \"@eslint/core\";\nimport { name, version } from \"../package.json\" with { type: 'json' };\nimport indentEmptyLines from \"./rules/indent-empty-lines.ts\";\n\nexport default {\n meta: {\n name,\n version,\n },\n rules: {\n \"indent-empty-lines\": indentEmptyLines,\n },\n} satisfies Plugin;\n"],"mappings":";;;;AAIA,qBAAe;CACb,MAAM;EACJ;EACA;CACD;CACD,OAAO,EACL,sBAAsBA,2BACvB;AACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/rules/indent-empty-lines.ts
|
|
3
|
+
var indent_empty_lines_default = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: "layout",
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Enforce indention on empty lines",
|
|
8
|
+
url: "https://github.com/funmaker/eslint-plugin-indent-empty-lines/blob/master/docs/rules/indent-empty-lines.md"
|
|
9
|
+
},
|
|
10
|
+
fixable: "whitespace",
|
|
11
|
+
schema: [{ oneOf: [{ enum: ["tab"] }, {
|
|
12
|
+
type: "integer",
|
|
13
|
+
minimum: 0
|
|
14
|
+
}] }],
|
|
15
|
+
defaultOptions: [2]
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
const sourceCode = context.sourceCode;
|
|
19
|
+
return { Program: function checkTrailingSpaces(node) {
|
|
20
|
+
const lines = sourceCode.lines, indentRE = /^[ \t]*/, bracketRE = /^[ \t]*[)}\]]/, padOption = context.options[0] === void 0 ? 2 : context.options[0], padding = padOption === "tab" ? " " : " ".repeat(padOption), paddingName = padOption === "tab" ? "tabs" : "spaces", linesPos = [];
|
|
21
|
+
let desiredIndent = "", currentPos = 0;
|
|
22
|
+
for (const line of lines) {
|
|
23
|
+
linesPos.push(currentPos);
|
|
24
|
+
currentPos += line.length + 1;
|
|
25
|
+
}
|
|
26
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
27
|
+
const line = lines[i];
|
|
28
|
+
const match = indentRE.exec(line);
|
|
29
|
+
if (!match) continue;
|
|
30
|
+
const currentIndent = match[0];
|
|
31
|
+
if (line === currentIndent) {
|
|
32
|
+
if (currentIndent !== desiredIndent) {
|
|
33
|
+
const range = [linesPos[i], linesPos[i] + currentIndent.length];
|
|
34
|
+
context.report({
|
|
35
|
+
node,
|
|
36
|
+
loc: {
|
|
37
|
+
start: {
|
|
38
|
+
line: i + 1,
|
|
39
|
+
column: 0
|
|
40
|
+
},
|
|
41
|
+
end: {
|
|
42
|
+
line: i + 1,
|
|
43
|
+
column: currentIndent.length
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
message: `Empty line not indented correctly. (expected ${desiredIndent.length} ${paddingName}, found ${currentIndent.length})`,
|
|
47
|
+
fix(fixer) {
|
|
48
|
+
return fixer.replaceTextRange(range, desiredIndent);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
} else if (bracketRE.exec(line)) desiredIndent = currentIndent + padding;
|
|
53
|
+
else desiredIndent = currentIndent;
|
|
54
|
+
}
|
|
55
|
+
} };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
exports.indent_empty_lines_default = indent_empty_lines_default;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region src/rules/indent-empty-lines.ts
|
|
2
|
+
var indent_empty_lines_default = {
|
|
3
|
+
meta: {
|
|
4
|
+
type: "layout",
|
|
5
|
+
docs: {
|
|
6
|
+
description: "Enforce indention on empty lines",
|
|
7
|
+
url: "https://github.com/funmaker/eslint-plugin-indent-empty-lines/blob/master/docs/rules/indent-empty-lines.md"
|
|
8
|
+
},
|
|
9
|
+
fixable: "whitespace",
|
|
10
|
+
schema: [{ oneOf: [{ enum: ["tab"] }, {
|
|
11
|
+
type: "integer",
|
|
12
|
+
minimum: 0
|
|
13
|
+
}] }],
|
|
14
|
+
defaultOptions: [2]
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
const sourceCode = context.sourceCode;
|
|
18
|
+
return { Program: function checkTrailingSpaces(node) {
|
|
19
|
+
const lines = sourceCode.lines, indentRE = /^[ \t]*/, bracketRE = /^[ \t]*[)}\]]/, padOption = context.options[0] === void 0 ? 2 : context.options[0], padding = padOption === "tab" ? " " : " ".repeat(padOption), paddingName = padOption === "tab" ? "tabs" : "spaces", linesPos = [];
|
|
20
|
+
let desiredIndent = "", currentPos = 0;
|
|
21
|
+
for (const line of lines) {
|
|
22
|
+
linesPos.push(currentPos);
|
|
23
|
+
currentPos += line.length + 1;
|
|
24
|
+
}
|
|
25
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
26
|
+
const line = lines[i];
|
|
27
|
+
const match = indentRE.exec(line);
|
|
28
|
+
if (!match) continue;
|
|
29
|
+
const currentIndent = match[0];
|
|
30
|
+
if (line === currentIndent) {
|
|
31
|
+
if (currentIndent !== desiredIndent) {
|
|
32
|
+
const range = [linesPos[i], linesPos[i] + currentIndent.length];
|
|
33
|
+
context.report({
|
|
34
|
+
node,
|
|
35
|
+
loc: {
|
|
36
|
+
start: {
|
|
37
|
+
line: i + 1,
|
|
38
|
+
column: 0
|
|
39
|
+
},
|
|
40
|
+
end: {
|
|
41
|
+
line: i + 1,
|
|
42
|
+
column: currentIndent.length
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
message: `Empty line not indented correctly. (expected ${desiredIndent.length} ${paddingName}, found ${currentIndent.length})`,
|
|
46
|
+
fix(fixer) {
|
|
47
|
+
return fixer.replaceTextRange(range, desiredIndent);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
} else if (bracketRE.exec(line)) desiredIndent = currentIndent + padding;
|
|
52
|
+
else desiredIndent = currentIndent;
|
|
53
|
+
}
|
|
54
|
+
} };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { indent_empty_lines_default };
|
|
60
|
+
//# sourceMappingURL=indent-empty-lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indent-empty-lines.js","names":[],"sources":["../../src/rules/indent-empty-lines.ts"],"sourcesContent":["import type { Rule } from 'eslint'\n\nexport default {\n meta: {\n type: \"layout\",\n docs: {\n description: \"Enforce indention on empty lines\",\n url: \"https://github.com/funmaker/eslint-plugin-indent-empty-lines/blob/master/docs/rules/indent-empty-lines.md\",\n },\n fixable: \"whitespace\",\n schema: [{\n oneOf: [\n { enum: [\"tab\"] },\n { type: \"integer\", minimum: 0 },\n ],\n }],\n defaultOptions: [2],\n },\n \n create(context) {\n const sourceCode = context.sourceCode;\n \n return {\n Program: function checkTrailingSpaces(node) {\n const lines = sourceCode.lines,\n indentRE = /^[ \\t]*/,\n bracketRE = /^[ \\t]*[)}\\]]/,\n padOption = context.options[0] === undefined ? 2 : context.options[0],\n padding = padOption === \"tab\" ? \"\\t\" : \" \".repeat(padOption),\n paddingName = padOption === \"tab\" ? \"tabs\" : \"spaces\",\n linesPos = [];\n \n let desiredIndent = \"\",\n currentPos = 0;\n \n for(const line of lines) {\n linesPos.push(currentPos);\n currentPos += line.length + 1; // assume LF line breaks\n }\n \n for(let i = lines.length - 1; i >= 0; i--) {\n const line = lines[i];\n const match = indentRE.exec(line);\n if(!match) continue;\n \n const currentIndent = match[0];\n \n if(line === currentIndent) { // empty\n if(currentIndent !== desiredIndent) {\n const range = [\n linesPos[i],\n linesPos[i] + currentIndent.length,\n ] satisfies [number, number];\n \n context.report({\n node,\n loc: {\n start: { line: i + 1, column: 0 },\n end: { line: i + 1, column: currentIndent.length },\n },\n message: `Empty line not indented correctly. (expected ${desiredIndent.length} ${paddingName}, found ${currentIndent.length})`,\n fix(fixer) {\n return fixer.replaceTextRange(range, desiredIndent);\n },\n });\n }\n } else if(bracketRE.exec(line)) {\n desiredIndent = currentIndent + padding;\n } else {\n desiredIndent = currentIndent;\n }\n }\n },\n };\n },\n} satisfies Rule.RuleModule;\n"],"mappings":";AAEA,iCAAe;CACX,MAAM;EACF,MAAM;EACN,MAAM;GACF,aAAa;GACb,KAAK;EACR;EACD,SAAS;EACT,QAAQ,CAAC,EACL,OAAO,CACH,EAAE,MAAM,CAAC,KAAM,EAAE,GACjB;GAAE,MAAM;GAAW,SAAS;EAAG,CAClC,EACJ,CAAC;EACF,gBAAgB,CAAC,CAAE;CACtB;CAED,OAAO,SAAS;EACZ,MAAM,aAAa,QAAQ;AAE3B,SAAO,EACH,SAAS,SAAS,oBAAoB,MAAM;GACxC,MAAM,QAAQ,WAAW,OACnB,WAAW,WACX,YAAY,iBACZ,YAAY,QAAQ,QAAQ,gBAAmB,IAAI,QAAQ,QAAQ,IACnE,UAAU,cAAc,QAAQ,MAAO,IAAI,OAAO,UAAU,EAC5D,cAAc,cAAc,QAAQ,SAAS,UAC7C,WAAW,CAAE;GAEnB,IAAI,gBAAgB,IAChB,aAAa;AAEjB,QAAI,MAAM,QAAQ,OAAO;AACrB,aAAS,KAAK,WAAW;AACzB,kBAAc,KAAK,SAAS;GAC/B;AAED,QAAI,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;IACvC,MAAM,OAAO,MAAM;IACnB,MAAM,QAAQ,SAAS,KAAK,KAAK;AACjC,SAAI,MAAO;IAEX,MAAM,gBAAgB,MAAM;AAE5B,QAAG,SAAS,eACR;SAAG,kBAAkB,eAAe;MAChC,MAAM,QAAQ,CACV,SAAS,IACT,SAAS,KAAK,cAAc,MAC/B;AAED,cAAQ,OAAO;OACX;OACA,KAAK;QACD,OAAO;SAAE,MAAM,IAAI;SAAG,QAAQ;QAAG;QACjC,KAAK;SAAE,MAAM,IAAI;SAAG,QAAQ,cAAc;QAAQ;OACrD;OACD,UAAU,+CAA+C,cAAc,OAAO,GAAG,YAAY,UAAU,cAAc,OAAO;OAC5H,IAAI,OAAO;AACP,eAAO,MAAM,iBAAiB,OAAO,cAAc;OACtD;MACJ,EAAC;KACL;eACK,UAAU,KAAK,KAAK,CAC1B,iBAAgB,gBAAgB;QAEhC,iBAAgB;GAEvB;EACJ,EACJ;CACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,35 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-indent-empty-lines",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Enforce indention on empty lines",
|
|
5
|
-
"
|
|
5
|
+
"author": "Fun Maker <funmaker95@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/funmaker/eslint-plugin-indent-empty-lines#readme",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
"import": "./index.mjs",
|
|
12
|
+
"require": "./index.js"
|
|
13
|
+
},
|
|
6
14
|
"scripts": {
|
|
7
|
-
"
|
|
15
|
+
"build": "tsdown",
|
|
16
|
+
"lint": "eslint",
|
|
17
|
+
"lint-fix": "eslint --fix",
|
|
18
|
+
"test": "mocha 'tests/**/*.ts'"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20.0.0"
|
|
8
22
|
},
|
|
9
23
|
"repository": {
|
|
10
24
|
"type": "git",
|
|
11
25
|
"url": "git+https://github.com/funmaker/eslint-plugin-indent-empty-lines.git"
|
|
12
26
|
},
|
|
13
|
-
"author": "Fun Maker <funmaker95@gmail.com>",
|
|
14
|
-
"license": "MIT",
|
|
15
27
|
"bugs": {
|
|
16
28
|
"url": "https://github.com/funmaker/eslint-plugin-indent-empty-lines/issues"
|
|
17
29
|
},
|
|
18
|
-
"homepage": "https://github.com/funmaker/eslint-plugin-indent-empty-lines#readme",
|
|
19
30
|
"devDependencies": {
|
|
20
|
-
"eslint": "^
|
|
21
|
-
"mocha": "^
|
|
31
|
+
"@eslint/compat": "^1.4.1",
|
|
32
|
+
"@types/mocha": "^10.0.10",
|
|
33
|
+
"@types/node": "^25.0.10",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8.53.1",
|
|
35
|
+
"@typescript-eslint/parser": "^8.53.1",
|
|
36
|
+
"mocha": "^11.7.5",
|
|
37
|
+
"tsdown": "^0.12.9",
|
|
38
|
+
"tsx": "^4.21.0",
|
|
39
|
+
"typescript": "^5.9.3"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"eslint": ">=9.0.0"
|
|
22
43
|
},
|
|
23
|
-
"dependencies": {},
|
|
24
44
|
"files": [
|
|
25
|
-
"
|
|
45
|
+
"dist/**/*"
|
|
26
46
|
],
|
|
27
47
|
"keywords": [
|
|
28
48
|
"eslint",
|
|
29
49
|
"eslintplugin",
|
|
30
50
|
"eslint-plugin"
|
|
31
|
-
]
|
|
32
|
-
"engines": {
|
|
33
|
-
"node": ">=0.10.0"
|
|
34
|
-
}
|
|
51
|
+
]
|
|
35
52
|
}
|
package/lib/index.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
meta: {
|
|
5
|
-
docs: {
|
|
6
|
-
description: "Enforce indention on empty lines",
|
|
7
|
-
category: "Stylistic Issues",
|
|
8
|
-
recommended: false,
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
fixable: "whitespace",
|
|
12
|
-
|
|
13
|
-
schema: [{
|
|
14
|
-
oneOf: [
|
|
15
|
-
{ enum: ["tab"] },
|
|
16
|
-
{ type: "integer", minimum: 0 },
|
|
17
|
-
],
|
|
18
|
-
}],
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
create(context) {
|
|
22
|
-
const sourceCode = context.getSourceCode();
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
Program: function checkTrailingSpaces(node) {
|
|
26
|
-
const lines = sourceCode.lines,
|
|
27
|
-
indentRE = /^[ \t]*/,
|
|
28
|
-
bracketRE = /^[ \t]*[)}\]]/,
|
|
29
|
-
padOption = context.options[0] === undefined ? 2 : context.options[0],
|
|
30
|
-
padding = padOption === "tab" ? "\t" : " ".repeat(padOption),
|
|
31
|
-
paddingName = padOption === "tab" ? "tabs" : "spaces",
|
|
32
|
-
linesPos = [];
|
|
33
|
-
|
|
34
|
-
let desiredIndent = "",
|
|
35
|
-
currentPos = 0;
|
|
36
|
-
|
|
37
|
-
for(const line of lines) {
|
|
38
|
-
linesPos.push(currentPos);
|
|
39
|
-
currentPos += line.length + 1; // assume LF line breaks
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
for(let i = lines.length - 1; i >= 0; i--) {
|
|
43
|
-
const line = lines[i];
|
|
44
|
-
const currentIndent = indentRE.exec(line)[0];
|
|
45
|
-
|
|
46
|
-
if(line === currentIndent) { // empty
|
|
47
|
-
if(currentIndent !== desiredIndent) {
|
|
48
|
-
const range = [
|
|
49
|
-
linesPos[i],
|
|
50
|
-
linesPos[i] + currentIndent.length,
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
context.report({
|
|
54
|
-
node,
|
|
55
|
-
loc: {
|
|
56
|
-
start: { line: i + 1, column: 0 },
|
|
57
|
-
end: { line: i + 1, column: currentIndent.length },
|
|
58
|
-
},
|
|
59
|
-
message: `Empty line not indented correctly. (expected ${desiredIndent.length} ${paddingName}, found ${currentIndent.length})`,
|
|
60
|
-
fix(fixer) {
|
|
61
|
-
return fixer.replaceTextRange(range, desiredIndent);
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
} else if(bracketRE.exec(line)) {
|
|
66
|
-
desiredIndent = currentIndent + padding;
|
|
67
|
-
} else {
|
|
68
|
-
desiredIndent = currentIndent;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
};
|