eslint-plugin-indent-empty-lines 1.0.2 → 2.0.1

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 CHANGED
@@ -19,7 +19,30 @@ $ npm install --save-dev eslint-plugin-indent-empty-lines
19
19
 
20
20
  ## Usage
21
21
 
22
- Add `indent-empty-lines` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
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,8 @@
1
+ import { recommended_default } from "./recommended.js";
2
+
3
+ //#region src/configs/index.ts
4
+ var configs_default = { recommended: recommended_default };
5
+
6
+ //#endregion
7
+ export { configs_default };
8
+ //# sourceMappingURL=index.js.map
@@ -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,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,90 @@
1
+
2
+ //#region package.json
3
+ var name = "eslint-plugin-indent-empty-lines";
4
+ var version = "2.0.1";
5
+
6
+ //#endregion
7
+ //#region src/rules/indent-empty-lines.ts
8
+ var indent_empty_lines_default = {
9
+ meta: {
10
+ type: "layout",
11
+ docs: {
12
+ description: "Enforce indention on empty lines",
13
+ url: "https://github.com/funmaker/eslint-plugin-indent-empty-lines/blob/master/docs/rules/indent-empty-lines.md"
14
+ },
15
+ fixable: "whitespace",
16
+ schema: [{ oneOf: [{ enum: ["tab"] }, {
17
+ type: "integer",
18
+ minimum: 0
19
+ }] }],
20
+ defaultOptions: [2]
21
+ },
22
+ create(context) {
23
+ const sourceCode = context.sourceCode;
24
+ return { Program: function checkTrailingSpaces(node) {
25
+ 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 = [];
26
+ let desiredIndent = "", currentPos = 0;
27
+ for (const line of lines) {
28
+ linesPos.push(currentPos);
29
+ currentPos += line.length + 1;
30
+ }
31
+ for (let i = lines.length - 1; i >= 0; i--) {
32
+ const line = lines[i];
33
+ const match = indentRE.exec(line);
34
+ if (!match) continue;
35
+ const currentIndent = match[0];
36
+ if (line === currentIndent) {
37
+ if (currentIndent !== desiredIndent) {
38
+ const range = [linesPos[i], linesPos[i] + currentIndent.length];
39
+ context.report({
40
+ node,
41
+ loc: {
42
+ start: {
43
+ line: i + 1,
44
+ column: 0
45
+ },
46
+ end: {
47
+ line: i + 1,
48
+ column: currentIndent.length
49
+ }
50
+ },
51
+ message: `Empty line not indented correctly. (expected ${desiredIndent.length} ${paddingName}, found ${currentIndent.length})`,
52
+ fix(fixer) {
53
+ return fixer.replaceTextRange(range, desiredIndent);
54
+ }
55
+ });
56
+ }
57
+ } else if (bracketRE.exec(line)) desiredIndent = currentIndent + padding;
58
+ else desiredIndent = currentIndent;
59
+ }
60
+ } };
61
+ }
62
+ };
63
+
64
+ //#endregion
65
+ //#region src/plugin.ts
66
+ var plugin_default = {
67
+ meta: {
68
+ name,
69
+ version
70
+ },
71
+ rules: { "indent-empty-lines": indent_empty_lines_default }
72
+ };
73
+
74
+ //#endregion
75
+ //#region src/configs/recommended.ts
76
+ var recommended_default = {
77
+ plugins: { "indent-empty-lines": plugin_default },
78
+ rules: { "indent-empty-lines/indent-empty-lines": ["warn", 2] }
79
+ };
80
+
81
+ //#endregion
82
+ //#region src/configs/index.ts
83
+ var configs_default = { recommended: recommended_default };
84
+
85
+ //#endregion
86
+ //#region src/index.ts
87
+ var src_default = Object.assign(plugin_default, { configs: configs_default });
88
+
89
+ //#endregion
90
+ module.exports = src_default;
@@ -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"}
@@ -0,0 +1,7 @@
1
+ //#region package.json
2
+ var name = "eslint-plugin-indent-empty-lines";
3
+ var version = "2.0.1";
4
+
5
+ //#endregion
6
+ export { name, version };
7
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"eslint-plugin-indent-empty-lines\",\n \"version\": \"2.0.1\",\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 \"types\": \"dist/index.d.ts\",\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.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
+ //#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,53 @@
1
1
  {
2
2
  "name": "eslint-plugin-indent-empty-lines",
3
- "version": "1.0.2",
3
+ "version": "2.0.1",
4
4
  "description": "Enforce indention on empty lines",
5
- "main": "lib/index.js",
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
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ "import": "./index.mjs",
13
+ "require": "./index.js"
14
+ },
6
15
  "scripts": {
7
- "test": "mocha tests --recursive"
16
+ "build": "tsdown",
17
+ "lint": "eslint",
18
+ "lint-fix": "eslint --fix",
19
+ "test": "mocha 'tests/**/*.ts'"
20
+ },
21
+ "engines": {
22
+ "node": ">=20.0.0"
8
23
  },
9
24
  "repository": {
10
25
  "type": "git",
11
26
  "url": "git+https://github.com/funmaker/eslint-plugin-indent-empty-lines.git"
12
27
  },
13
- "author": "Fun Maker <funmaker95@gmail.com>",
14
- "license": "MIT",
15
28
  "bugs": {
16
29
  "url": "https://github.com/funmaker/eslint-plugin-indent-empty-lines/issues"
17
30
  },
18
- "homepage": "https://github.com/funmaker/eslint-plugin-indent-empty-lines#readme",
19
31
  "devDependencies": {
20
- "eslint": "^7.1.0",
21
- "mocha": "^7.2.0"
32
+ "@eslint/compat": "^1.4.1",
33
+ "@types/mocha": "^10.0.10",
34
+ "@types/node": "^25.0.10",
35
+ "@typescript-eslint/eslint-plugin": "^8.53.1",
36
+ "@typescript-eslint/parser": "^8.53.1",
37
+ "mocha": "^11.7.5",
38
+ "tsdown": "^0.12.9",
39
+ "tsx": "^4.21.0",
40
+ "typescript": "^5.9.3"
41
+ },
42
+ "peerDependencies": {
43
+ "eslint": ">=9.0.0"
22
44
  },
23
- "dependencies": {},
24
45
  "files": [
25
- "lib/**/*"
46
+ "dist/**/*"
26
47
  ],
27
48
  "keywords": [
28
49
  "eslint",
29
50
  "eslintplugin",
30
51
  "eslint-plugin"
31
- ],
32
- "engines": {
33
- "node": ">=0.10.0"
34
- }
52
+ ]
35
53
  }
package/lib/index.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- const indentEmptyLines = require("./rules/indent-empty-lines");
4
-
5
- module.exports.rules = {
6
- "indent-empty-lines": indentEmptyLines,
7
- }
@@ -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
- };