@progressive-victory/eslint-plugin-index-file 0.0.5 → 0.0.6
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/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -166
- package/dist/index.js.map +1 -7
- package/dist/rules/enforce-index-usage.d.ts +4 -0
- package/dist/rules/enforce-index-usage.d.ts.map +1 -0
- package/dist/rules/enforce-index-usage.js +46 -0
- package/dist/rules/enforce-index-usage.js.map +1 -0
- package/dist/rules/enforce-index-usage.test.d.ts +2 -0
- package/dist/rules/enforce-index-usage.test.d.ts.map +1 -0
- package/dist/rules/enforce-index-usage.test.js +40 -0
- package/dist/rules/enforce-index-usage.test.js.map +1 -0
- package/dist/rules/index.d.ts +3 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +3 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +3 -0
- package/dist/utils.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const plugin: {
|
|
2
|
+
configs: {
|
|
3
|
+
readonly recommended: {
|
|
4
|
+
plugins: {
|
|
5
|
+
"eslint-index-file-plugin": /*elided*/ any;
|
|
6
|
+
};
|
|
7
|
+
enforceIndexUsageRule: import("@typescript-eslint/utils/ts-eslint").RuleModule<"notExportedInIndex" | "noIndexPresent", [], import("./utils").IndexFileDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
meta: {
|
|
13
|
+
name: string;
|
|
14
|
+
version: string;
|
|
15
|
+
};
|
|
16
|
+
enforceIndexUsageRule: import("@typescript-eslint/utils/ts-eslint").RuleModule<"notExportedInIndex" | "noIndexPresent", [], import("./utils").IndexFileDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export default plugin;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;CAQX,CAAA;AASD,eAAe,MAAM,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,170 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
name: "@progressive-victory/eslint-plugin-index-file",
|
|
11
|
-
version: "0.0.4",
|
|
12
|
-
description: "Plugin that enforces the use of index files with eslint.",
|
|
13
|
-
homepage: "https://github.com/Progressive-Victory/eslint-index-file-plugin#readme",
|
|
14
|
-
private: false,
|
|
15
|
-
bugs: {
|
|
16
|
-
url: "https://github.com/Progressive-Victory/eslint-index-file-plugin/issues"
|
|
17
|
-
},
|
|
18
|
-
repository: {
|
|
19
|
-
type: "git",
|
|
20
|
-
url: "git+https://github.com/Progressive-Victory/eslint-index-file-plugin.git"
|
|
21
|
-
},
|
|
22
|
-
license: "ISC",
|
|
23
|
-
author: "sH3llH0und",
|
|
24
|
-
type: "module",
|
|
25
|
-
packageManager: "pnpm@10.30.2",
|
|
26
|
-
main: "dist/index.js",
|
|
27
|
-
exports: {
|
|
28
|
-
"./*.js": {
|
|
29
|
-
types: "./*.d.ts",
|
|
30
|
-
require: "./*.js",
|
|
31
|
-
import: "./*.js"
|
|
1
|
+
import { enforceIndexUsageRule } from "./rules";
|
|
2
|
+
const { name, version } =
|
|
3
|
+
// eslint-diable-next-line @typescript-eslint/no-require-imports
|
|
4
|
+
require("../package.json");
|
|
5
|
+
const plugin = {
|
|
6
|
+
configs: {
|
|
7
|
+
get recommended() {
|
|
8
|
+
return recommended;
|
|
32
9
|
}
|
|
33
|
-
},
|
|
34
|
-
scripts: {
|
|
35
|
-
build: "node esbuild.config.js",
|
|
36
|
-
test: "pnpm build && pnpm vitest --silent=false"
|
|
37
|
-
},
|
|
38
|
-
devDependencies: {
|
|
39
|
-
"@types/node": "^25.9.1",
|
|
40
|
-
"@typescript-eslint/rule-tester": "^8.60.1",
|
|
41
|
-
esbuild: "^0.28.0",
|
|
42
|
-
globals: "^17.6.0",
|
|
43
|
-
prettier: "^3.8.3",
|
|
44
|
-
typescript: "^6.0.3",
|
|
45
|
-
"typescript-eslint": "^8.60.1",
|
|
46
|
-
vitest: "^4.1.8"
|
|
47
|
-
},
|
|
48
|
-
dependencies: {
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^8.60.1",
|
|
50
|
-
"@typescript-eslint/parser": "^8.60.1",
|
|
51
|
-
"@typescript-eslint/utils": "^8.60.1",
|
|
52
|
-
eslint: "^10.4.1"
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// src/utils.ts
|
|
59
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
60
|
-
var createRule = ESLintUtils.RuleCreator(
|
|
61
|
-
(name2) => `https://github.com/import-js/eslint-plugin-import/wiki/${name2}`
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// src/rules/enforce-index-usage.ts
|
|
65
|
-
import path from "node:path";
|
|
66
|
-
import fs from "fs";
|
|
67
|
-
var enforceIndexUsageRule = createRule({
|
|
68
|
-
create(context) {
|
|
69
|
-
return {
|
|
70
|
-
ExportNamedDeclaration(node) {
|
|
71
|
-
console.log("doing shit");
|
|
72
|
-
const cwd = context.cwd;
|
|
73
|
-
const cwdFiles = fs.readdirSync(cwd);
|
|
74
|
-
const index = cwdFiles.find((x) => x === "index.ts");
|
|
75
|
-
if (!index) context.report({
|
|
76
|
-
messageId: "noIndexPresent",
|
|
77
|
-
node
|
|
78
|
-
});
|
|
79
|
-
const fileNameArr = context.filename.split(".");
|
|
80
|
-
const fileName = fileNameArr[fileNameArr.length - 1];
|
|
81
|
-
const indexContent = fs.readFileSync(path.join(cwd, "index.ts")).toString();
|
|
82
|
-
if (!indexContent.includes(`export * from './${fileName}.js`)) context.report({
|
|
83
|
-
messageId: "notExportedInIndex",
|
|
84
|
-
node
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
},
|
|
89
|
-
meta: {
|
|
90
|
-
docs: {
|
|
91
|
-
description: "Enforces the usage of index files within code.",
|
|
92
|
-
recommended: true,
|
|
93
|
-
requiresTypeChecking: false
|
|
94
|
-
},
|
|
95
|
-
messages: {
|
|
96
|
-
notExportedInIndex: "Export statement not accompanied by index file entry.",
|
|
97
|
-
noIndexPresent: "Could not find index file in working directory."
|
|
98
10
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
},
|
|
102
|
-
name: "enforce-index-usage",
|
|
103
|
-
defaultOptions: []
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// src/rules/enforce-index-usage.test.ts
|
|
107
|
-
import path2 from "path";
|
|
108
|
-
import tseslint from "typescript-eslint";
|
|
109
|
-
import { RuleTester } from "@typescript-eslint/rule-tester";
|
|
110
|
-
import * as vitest from "vitest";
|
|
111
|
-
RuleTester.afterAll = vitest.afterAll;
|
|
112
|
-
RuleTester.it = vitest.it;
|
|
113
|
-
RuleTester.itOnly = vitest.it.only;
|
|
114
|
-
RuleTester.describe = vitest.describe;
|
|
115
|
-
var ruleTester = new RuleTester({
|
|
116
|
-
languageOptions: {
|
|
117
|
-
parser: tseslint.parser,
|
|
118
|
-
parserOptions: {
|
|
119
|
-
projectService: {
|
|
120
|
-
allowDefaultProject: ["*.js"],
|
|
121
|
-
defaultProject: "tsconfig.json"
|
|
122
|
-
},
|
|
123
|
-
tsconfigRootDir: path2.join(import.meta.dirname, "../..")
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
ruleTester.run("enforce-index-usage", enforceIndexUsageRule, {
|
|
128
|
-
valid: [
|
|
129
|
-
{
|
|
130
|
-
code: `export const foo = bar`
|
|
131
|
-
}
|
|
132
|
-
],
|
|
133
|
-
invalid: [
|
|
134
|
-
{
|
|
135
|
-
code: `export const bar = foo`,
|
|
136
|
-
errors: [
|
|
137
|
-
{
|
|
138
|
-
messageId: "notExportedInIndex",
|
|
139
|
-
suggestions: []
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
}
|
|
143
|
-
]
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// src/index.ts
|
|
147
|
-
var { name, version } = (
|
|
148
|
-
// eslint-diable-next-line @typescript-eslint/no-require-imports
|
|
149
|
-
require_package()
|
|
150
|
-
);
|
|
151
|
-
var plugin = {
|
|
152
|
-
configs: {
|
|
153
|
-
get recommended() {
|
|
154
|
-
return recommended;
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
meta: { name, version },
|
|
158
|
-
enforceIndexUsageRule
|
|
11
|
+
meta: { name, version },
|
|
12
|
+
enforceIndexUsageRule
|
|
159
13
|
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
};
|
|
166
|
-
var index_default = plugin;
|
|
167
|
-
export {
|
|
168
|
-
index_default as default
|
|
14
|
+
const recommended = {
|
|
15
|
+
plugins: {
|
|
16
|
+
"eslint-index-file-plugin": plugin
|
|
17
|
+
},
|
|
18
|
+
enforceIndexUsageRule
|
|
169
19
|
};
|
|
170
|
-
|
|
20
|
+
export default plugin;
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../package.json", "../src/utils.ts", "../src/rules/enforce-index-usage.ts", "../src/rules/enforce-index-usage.test.ts", "../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["{\n \"name\": \"@progressive-victory/eslint-plugin-index-file\",\n \"version\": \"0.0.4\",\n \"description\": \"Plugin that enforces the use of index files with eslint.\",\n \"homepage\": \"https://github.com/Progressive-Victory/eslint-index-file-plugin#readme\",\n \"private\": false,\n \"bugs\": {\n \"url\": \"https://github.com/Progressive-Victory/eslint-index-file-plugin/issues\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/Progressive-Victory/eslint-index-file-plugin.git\"\n },\n \"license\": \"ISC\",\n \"author\": \"sH3llH0und\",\n \"type\": \"module\",\n \"packageManager\": \"pnpm@10.30.2\",\n \"main\": \"dist/index.js\",\n \"exports\": {\n \"./*.js\": {\n \"types\": \"./*.d.ts\",\n \"require\": \"./*.js\",\n \"import\": \"./*.js\"\n }\n },\n \"scripts\": {\n \"build\": \"node esbuild.config.js\",\n \"test\": \"pnpm build && pnpm vitest --silent=false\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^25.9.1\",\n \"@typescript-eslint/rule-tester\": \"^8.60.1\",\n \"esbuild\": \"^0.28.0\",\n \"globals\": \"^17.6.0\",\n \"prettier\": \"^3.8.3\",\n \"typescript\": \"^6.0.3\",\n \"typescript-eslint\": \"^8.60.1\",\n \"vitest\": \"^4.1.8\"\n },\n \"dependencies\": {\n \"@typescript-eslint/eslint-plugin\": \"^8.60.1\",\n \"@typescript-eslint/parser\": \"^8.60.1\",\n \"@typescript-eslint/utils\": \"^8.60.1\",\n \"eslint\": \"^10.4.1\"\n }\n}\n", "import {ESLintUtils} from \"@typescript-eslint/utils\"\r\n\r\nexport interface IndexFileDocs {\r\n description: string;\r\n recommended?: boolean;\r\n requiresTypeChecking?: boolean;\r\n}\r\n\r\nexport const createRule = ESLintUtils.RuleCreator<IndexFileDocs>(\r\n (name) => `https://github.com/import-js/eslint-plugin-import/wiki/${name}`\r\n)", "//import {ESLintUtils} from \"@typescript-eslint/utils\"\r\n\r\nimport { createRule } from \"../utils.js\"\r\nimport path from \"node:path\"\r\nimport fs from \"fs\"\r\n\r\nexport const enforceIndexUsageRule = createRule({\r\n create(context) {\r\n //const services = ESLintUtils.getParserServices(context);\r\n\r\n return {\r\n ExportNamedDeclaration(node) {\r\n console.log(\"doing shit\")\r\n const cwd = context.cwd\r\n const cwdFiles = fs.readdirSync(cwd)\r\n const index = cwdFiles.find(x => x === \"index.ts\")\r\n if(!index) context.report({\r\n messageId: 'noIndexPresent',\r\n node\r\n })\r\n\r\n const fileNameArr = context.filename.split('.')\r\n const fileName = fileNameArr[fileNameArr.length - 1]\r\n const indexContent = fs.readFileSync(path.join(cwd, \"index.ts\")).toString()\r\n if(!indexContent.includes(`export * from './${fileName}.js`)) context.report({\r\n messageId: \"notExportedInIndex\",\r\n node\r\n })\r\n }\r\n }\r\n },\r\n meta: {\r\n docs: {\r\n description: \"Enforces the usage of index files within code.\",\r\n recommended: true,\r\n requiresTypeChecking: false\r\n },\r\n messages: {\r\n notExportedInIndex: \"Export statement not accompanied by index file entry.\",\r\n noIndexPresent: \"Could not find index file in working directory.\"\r\n },\r\n type: \"problem\",\r\n schema: []\r\n },\r\n name: \"enforce-index-usage\",\r\n defaultOptions: []\r\n})", "import path from \"path\"\r\nimport tseslint from \"typescript-eslint\";\r\nimport { RuleTester } from \"@typescript-eslint/rule-tester\"\r\nimport * as vitest from \"vitest\"\r\n\r\nimport { enforceIndexUsageRule } from \"./enforce-index-usage\"\r\n\r\nRuleTester.afterAll = vitest.afterAll\r\nRuleTester.it = vitest.it\r\nRuleTester.itOnly = vitest.it.only\r\nRuleTester.describe = vitest.describe\r\n\r\nconst ruleTester = new RuleTester({\r\n languageOptions: {\r\n parser: tseslint.parser,\r\n parserOptions: {\r\n projectService: {\r\n allowDefaultProject: [\"*.js\"],\r\n defaultProject: \"tsconfig.json\"\r\n },\r\n tsconfigRootDir: path.join(import.meta.dirname, \"../..\")\r\n }\r\n }\r\n})\r\n\r\nruleTester.run(\"enforce-index-usage\", enforceIndexUsageRule, {\r\n valid: [\r\n {\r\n code: `export const foo = bar`\r\n }\r\n ],\r\n invalid: [\r\n {\r\n code: `export const bar = foo`,\r\n errors: [\r\n {\r\n messageId: \"notExportedInIndex\",\r\n suggestions: [\r\n ]\r\n }\r\n ]\r\n }\r\n ]\r\n})", "import {enforceIndexUsageRule} from \"./rules\"\r\n\r\nconst {name, version} =\r\n // eslint-diable-next-line @typescript-eslint/no-require-imports\r\n require(\"../package.json\") as typeof import(\"../package.json\")\r\n\r\nconst plugin = {\r\n configs: {\r\n get recommended() {\r\n return recommended\r\n }\r\n },\r\n meta: { name, version },\r\n enforceIndexUsageRule\r\n}\r\n\r\nconst recommended = {\r\n plugins: {\r\n \"eslint-index-file-plugin\": plugin\r\n },\r\n enforceIndexUsageRule\r\n}\r\n\r\nexport default plugin;"],
|
|
5
|
-
"mappings": ";;;;;;AAAA;AAAA;AAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,aAAe;AAAA,MACf,UAAY;AAAA,MACZ,SAAW;AAAA,MACX,MAAQ;AAAA,QACN,KAAO;AAAA,MACT;AAAA,MACA,YAAc;AAAA,QACZ,MAAQ;AAAA,QACR,KAAO;AAAA,MACT;AAAA,MACA,SAAW;AAAA,MACX,QAAU;AAAA,MACV,MAAQ;AAAA,MACR,gBAAkB;AAAA,MAClB,MAAQ;AAAA,MACR,SAAW;AAAA,QACT,UAAU;AAAA,UACR,OAAS;AAAA,UACT,SAAW;AAAA,UACX,QAAU;AAAA,QACZ;AAAA,MACF;AAAA,MACA,SAAW;AAAA,QACT,OAAS;AAAA,QACT,MAAQ;AAAA,MACV;AAAA,MACA,iBAAmB;AAAA,QACjB,eAAe;AAAA,QACf,kCAAkC;AAAA,QAClC,SAAW;AAAA,QACX,SAAW;AAAA,QACX,UAAY;AAAA,QACZ,YAAc;AAAA,QACd,qBAAqB;AAAA,QACrB,QAAU;AAAA,MACZ;AAAA,MACA,cAAgB;AAAA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EAAE;QACL,IAAI,WAAW;YACX,OAAO,WAAW,CAAA;QACtB,CAAC;KACJ;IACD,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;IACvB,qBAAqB;CACxB,CAAA;AAED,MAAM,WAAW,GAAG;IAChB,OAAO,EAAE;QACL,0BAA0B,EAAE,MAAM;KACrC;IACD,qBAAqB;CACxB,CAAA;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const enforceIndexUsageRule: import("@typescript-eslint/utils/ts-eslint").RuleModule<"notExportedInIndex" | "noIndexPresent", [], import("../utils.js").IndexFileDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
4
|
+
//# sourceMappingURL=enforce-index-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-index-usage.d.ts","sourceRoot":"","sources":["../../src/rules/enforce-index-usage.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,qBAAqB;;CAwChC,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//import {ESLintUtils} from "@typescript-eslint/utils"
|
|
2
|
+
import { createRule } from "../utils.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
export const enforceIndexUsageRule = createRule({
|
|
6
|
+
create(context) {
|
|
7
|
+
//const services = ESLintUtils.getParserServices(context);
|
|
8
|
+
return {
|
|
9
|
+
ExportNamedDeclaration(node) {
|
|
10
|
+
console.log("doing shit");
|
|
11
|
+
const cwd = context.cwd;
|
|
12
|
+
const cwdFiles = fs.readdirSync(cwd);
|
|
13
|
+
const index = cwdFiles.find(x => x === "index.ts");
|
|
14
|
+
if (!index)
|
|
15
|
+
context.report({
|
|
16
|
+
messageId: 'noIndexPresent',
|
|
17
|
+
node
|
|
18
|
+
});
|
|
19
|
+
const fileNameArr = context.filename.split('.');
|
|
20
|
+
const fileName = fileNameArr[fileNameArr.length - 1];
|
|
21
|
+
const indexContent = fs.readFileSync(path.join(cwd, "index.ts")).toString();
|
|
22
|
+
if (!indexContent.includes(`export * from './${fileName}.js`))
|
|
23
|
+
context.report({
|
|
24
|
+
messageId: "notExportedInIndex",
|
|
25
|
+
node
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
meta: {
|
|
31
|
+
docs: {
|
|
32
|
+
description: "Enforces the usage of index files within code.",
|
|
33
|
+
recommended: true,
|
|
34
|
+
requiresTypeChecking: false
|
|
35
|
+
},
|
|
36
|
+
messages: {
|
|
37
|
+
notExportedInIndex: "Export statement not accompanied by index file entry.",
|
|
38
|
+
noIndexPresent: "Could not find index file in working directory."
|
|
39
|
+
},
|
|
40
|
+
type: "problem",
|
|
41
|
+
schema: []
|
|
42
|
+
},
|
|
43
|
+
name: "enforce-index-usage",
|
|
44
|
+
defaultOptions: []
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=enforce-index-usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-index-usage.js","sourceRoot":"","sources":["../../src/rules/enforce-index-usage.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAC;IAC5C,MAAM,CAAC,OAAO;QACV,0DAA0D;QAE1D,OAAO;YACH,sBAAsB,CAAC,IAAI;gBACvB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;gBACzB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;gBACvB,MAAM,QAAQ,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;gBACpC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,UAAU,CAAC,CAAA;gBAClD,IAAG,CAAC,KAAK;oBAAE,OAAO,CAAC,MAAM,CAAC;wBAClB,SAAS,EAAE,gBAAgB;wBAC3B,IAAI;qBACP,CAAC,CAAA;gBAEN,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBAC/C,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;gBACpD,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;gBAC3E,IAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,oBAAoB,QAAQ,KAAK,CAAC;oBAAE,OAAO,CAAC,MAAM,CAAC;wBACzE,SAAS,EAAE,oBAAoB;wBAC/B,IAAI;qBACP,CAAC,CAAA;YACN,CAAC;SACJ,CAAA;IACL,CAAC;IACD,IAAI,EAAE;QACF,IAAI,EAAE;YACF,WAAW,EAAE,gDAAgD;YAC7D,WAAW,EAAE,IAAI;YACjB,oBAAoB,EAAE,KAAK;SAC9B;QACD,QAAQ,EAAE;YACN,kBAAkB,EAAE,uDAAuD;YAC3E,cAAc,EAAE,iDAAiD;SACpE;QACD,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,EAAE;KACb;IACD,IAAI,EAAE,qBAAqB;IAC3B,cAAc,EAAE,EAAE;CACrB,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-index-usage.test.d.ts","sourceRoot":"","sources":["../../src/rules/enforce-index-usage.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import tseslint from "typescript-eslint";
|
|
3
|
+
import { RuleTester } from "@typescript-eslint/rule-tester";
|
|
4
|
+
import * as vitest from "vitest";
|
|
5
|
+
import { enforceIndexUsageRule } from "./enforce-index-usage";
|
|
6
|
+
RuleTester.afterAll = vitest.afterAll;
|
|
7
|
+
RuleTester.it = vitest.it;
|
|
8
|
+
RuleTester.itOnly = vitest.it.only;
|
|
9
|
+
RuleTester.describe = vitest.describe;
|
|
10
|
+
const ruleTester = new RuleTester({
|
|
11
|
+
languageOptions: {
|
|
12
|
+
parser: tseslint.parser,
|
|
13
|
+
parserOptions: {
|
|
14
|
+
projectService: {
|
|
15
|
+
allowDefaultProject: ["*.js"],
|
|
16
|
+
defaultProject: "tsconfig.json"
|
|
17
|
+
},
|
|
18
|
+
tsconfigRootDir: path.join(import.meta.dirname, "../..")
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
ruleTester.run("enforce-index-usage", enforceIndexUsageRule, {
|
|
23
|
+
valid: [
|
|
24
|
+
{
|
|
25
|
+
code: `export const foo = bar`
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
invalid: [
|
|
29
|
+
{
|
|
30
|
+
code: `export const bar = foo`,
|
|
31
|
+
errors: [
|
|
32
|
+
{
|
|
33
|
+
messageId: "notExportedInIndex",
|
|
34
|
+
suggestions: []
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=enforce-index-usage.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-index-usage.test.js","sourceRoot":"","sources":["../../src/rules/enforce-index-usage.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3D,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;AACrC,UAAU,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAA;AACzB,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI,CAAA;AAClC,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;AAErC,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;IAC9B,eAAe,EAAE;QACb,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,aAAa,EAAE;YACX,cAAc,EAAE;gBACZ,mBAAmB,EAAE,CAAC,MAAM,CAAC;gBAC7B,cAAc,EAAE,eAAe;aAClC;YACD,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;SAC3D;KACJ;CACJ,CAAC,CAAA;AAEF,UAAU,CAAC,GAAG,CAAC,qBAAqB,EAAE,qBAAqB,EAAE;IACzD,KAAK,EAAE;QACH;YACI,IAAI,EAAE,wBAAwB;SACjC;KACJ;IACD,OAAO,EAAE;QACL;YACI,IAAI,EAAE,wBAAwB;YAC9B,MAAM,EAAE;gBACJ;oBACI,SAAS,EAAE,oBAAoB;oBAC/B,WAAW,EAAE,EACZ;iBACJ;aACJ;SACJ;KACJ;CACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
export interface IndexFileDocs {
|
|
3
|
+
description: string;
|
|
4
|
+
recommended?: boolean;
|
|
5
|
+
requiresTypeChecking?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, IndexFileDocs>>) => ESLintUtils.RuleModule<MessageIds, Options, IndexFileDocs, ESLintUtils.RuleListener> & {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,0BAA0B,CAAA;AAEpD,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,eAAO,MAAM,UAAU;;CAEtB,CAAA"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,0BAA0B,CAAA;AAQpD,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CAC7C,CAAC,IAAI,EAAE,EAAE,CAAC,0DAA0D,IAAI,EAAE,CAC7E,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@progressive-victory/eslint-plugin-index-file",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Plugin that enforces the use of index files with eslint.",
|
|
5
5
|
"homepage": "https://github.com/Progressive-Victory/eslint-index-file-plugin#readme",
|
|
6
6
|
"private": false,
|