@progressive-victory/eslint-plugin-index-file 0.0.4 → 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.
@@ -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 ADDED
@@ -0,0 +1,21 @@
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;
9
+ }
10
+ },
11
+ meta: { name, version },
12
+ enforceIndexUsageRule
13
+ };
14
+ const recommended = {
15
+ plugins: {
16
+ "eslint-index-file-plugin": plugin
17
+ },
18
+ enforceIndexUsageRule
19
+ };
20
+ export default plugin;
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAA;AAE7C,MAAM,EAAC,IAAI,EAAE,OAAO,EAAC;AACjB,gEAAgE;AAChE,OAAO,CAAC,iBAAiB,CAAqC,CAAA;AAElE,MAAM,MAAM,GAAG;IACX,OAAO,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=enforce-index-usage.test.d.ts.map
@@ -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,3 @@
1
+ export * from './enforce-index-usage.js';
2
+ export * from './enforce-index-usage.test.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,3 @@
1
+ export * from './enforce-index-usage.js';
2
+ export * from './enforce-index-usage.test.js';
3
+ //# sourceMappingURL=index.js.map
@@ -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"}
@@ -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,3 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ export const createRule = ESLintUtils.RuleCreator((name) => `https://github.com/import-js/eslint-plugin-import/wiki/${name}`);
3
+ //# sourceMappingURL=utils.js.map
@@ -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.4",
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,