@bamboocss/eslint-plugin 1.12.1 → 1.12.3
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.cjs +79 -94
- package/dist/index.d.cts +40 -0
- package/dist/index.d.mts +41 -0
- package/dist/index.mjs +2130 -2316
- package/dist/utils/worker.cjs +155 -6
- package/dist/utils/worker.d.cts +53 -0
- package/dist/utils/worker.d.mts +54 -0
- package/dist/utils/worker.mjs +135 -4
- package/package.json +16 -16
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/utils--KVHU2cv.mjs +0 -164
- package/dist/utils--KVHU2cv.mjs.map +0 -1
- package/dist/utils-BbqZf2ZV.cjs +0 -217
- package/dist/utils-BbqZf2ZV.cjs.map +0 -1
package/dist/utils/worker.cjs
CHANGED
|
@@ -1,6 +1,155 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value:
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let synckit = require("synckit");
|
|
25
|
+
let _bamboocss_config = require("@bamboocss/config");
|
|
26
|
+
let _bamboocss_config_ts_path = require("@bamboocss/config/ts-path");
|
|
27
|
+
let _bamboocss_generator = require("@bamboocss/generator");
|
|
28
|
+
let micromatch = require("micromatch");
|
|
29
|
+
micromatch = __toESM(micromatch);
|
|
30
|
+
let path = require("path");
|
|
31
|
+
path = __toESM(path);
|
|
32
|
+
//#region src/utils/worker.ts
|
|
33
|
+
const contextCache = {};
|
|
34
|
+
async function getContext(options) {
|
|
35
|
+
if (process.env.NODE_ENV === "test") {
|
|
36
|
+
const { createGeneratorContext } = await import("../../tests/fixtures/create-context");
|
|
37
|
+
return createGeneratorContext({
|
|
38
|
+
exclude: ["**/Invalid.tsx", "**/bamboo.config.ts"],
|
|
39
|
+
importMap: "./bamboo",
|
|
40
|
+
include: ["**/*"],
|
|
41
|
+
jsxFactory: "styled"
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
const configPath = (0, _bamboocss_config.findConfig)({ cwd: options.configPath ?? options.currentFile });
|
|
45
|
+
if (!contextCache[configPath]) contextCache[configPath] = _getContext(configPath);
|
|
46
|
+
return contextCache[configPath];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function _getContext(configPath) {
|
|
50
|
+
if (!configPath) throw new Error("Invalid config path");
|
|
51
|
+
return new _bamboocss_generator.Generator(await (0, _bamboocss_config.loadConfig)({
|
|
52
|
+
cwd: path.default.dirname(configPath),
|
|
53
|
+
file: configPath
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
const filterDeprecatedTokens = (context, tokens) => {
|
|
57
|
+
return tokens.filter((token) => {
|
|
58
|
+
const value = typeof token === "string" ? token : token.category + "." + token.value;
|
|
59
|
+
return context.utility.tokens.isDeprecated(value);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
const filterInvalidTokens = (context, paths) => {
|
|
63
|
+
return paths.filter((path$2) => !context.utility.tokens.view.get(path$2));
|
|
64
|
+
};
|
|
65
|
+
const getPropertyCategory = (context, _attribute) => {
|
|
66
|
+
const attribute = resolveLongHand(context, _attribute) || _attribute;
|
|
67
|
+
const attributeConfig = context.utility.config[attribute];
|
|
68
|
+
return typeof attributeConfig?.values === "string" ? attributeConfig.values : void 0;
|
|
69
|
+
};
|
|
70
|
+
const isColorAttribute = (context, _attribute) => {
|
|
71
|
+
return getPropertyCategory(context, _attribute) === "colors";
|
|
72
|
+
};
|
|
73
|
+
const isColorToken = (context, value) => {
|
|
74
|
+
return Boolean(context.utility.tokens.view.categoryMap.get("colors")?.get(value));
|
|
75
|
+
};
|
|
76
|
+
function run(action, options, ...args) {
|
|
77
|
+
return runAsync(action, options, ...args);
|
|
78
|
+
}
|
|
79
|
+
async function runAsync(action, options, ...args) {
|
|
80
|
+
const context = await getContext(options);
|
|
81
|
+
switch (action) {
|
|
82
|
+
case "filterDeprecatedTokens": return filterDeprecatedTokens(context, ...args);
|
|
83
|
+
case "filterImports": return filterImports(context, ...args);
|
|
84
|
+
case "filterInvalidTokens": return filterInvalidTokens(context, ...args);
|
|
85
|
+
case "getJsxFactory": return getJsxFactory(context);
|
|
86
|
+
case "getPropCategory": return getPropertyCategory(context, ...args);
|
|
87
|
+
case "isColorAttribute": return isColorAttribute(context, ...args);
|
|
88
|
+
case "isColorToken": return isColorToken(context, ...args);
|
|
89
|
+
case "isValidFile": return isValidFile(context, options.currentFile);
|
|
90
|
+
case "isValidProperty": return isValidProperty(context, ...args);
|
|
91
|
+
case "matchFile": return matchFile(context, ...args);
|
|
92
|
+
case "matchImports": return matchImports(context, ...args);
|
|
93
|
+
case "resolveLongHand": return resolveLongHand(context, ...args);
|
|
94
|
+
case "resolveShorthands": return resolveShorthands(context, ...args);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const isValidFile = (context, fileName) => {
|
|
98
|
+
const { exclude, include } = context.config;
|
|
99
|
+
const cwd = context.config.cwd || process.cwd();
|
|
100
|
+
const relativePath = path.default.isAbsolute(fileName) ? path.default.relative(cwd, fileName) : fileName;
|
|
101
|
+
return micromatch.default.isMatch(relativePath, include, {
|
|
102
|
+
dot: true,
|
|
103
|
+
ignore: exclude
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const isValidProperty = (context, name, patternName) => {
|
|
107
|
+
if (context.isValidProperty(name)) return true;
|
|
108
|
+
if (!patternName) return false;
|
|
109
|
+
if (patternName === context.config.jsxFactory) return false;
|
|
110
|
+
const pattern = context.patterns.details.find((p) => p.baseName === patternName || p.jsx.includes(patternName))?.config.properties;
|
|
111
|
+
if (!pattern) return false;
|
|
112
|
+
return Object.keys(pattern).includes(name);
|
|
113
|
+
};
|
|
114
|
+
const matchFile = (context, name, imports) => {
|
|
115
|
+
return context.imports.file(imports).match(name);
|
|
116
|
+
};
|
|
117
|
+
const matchImports = (context, result) => {
|
|
118
|
+
return context.imports.match(result, (module_) => {
|
|
119
|
+
const { tsOptions } = context.parserOptions;
|
|
120
|
+
if (!tsOptions?.pathMappings) return;
|
|
121
|
+
return (0, _bamboocss_config_ts_path.resolveTsPathPattern)(tsOptions.pathMappings, module_);
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const filterImports = (context, imports) => {
|
|
125
|
+
return imports.filter((imp) => context.imports.match(imp, (module_) => {
|
|
126
|
+
const { tsOptions } = context.parserOptions;
|
|
127
|
+
if (!tsOptions?.pathMappings) return;
|
|
128
|
+
return (0, _bamboocss_config_ts_path.resolveTsPathPattern)(tsOptions.pathMappings, module_);
|
|
129
|
+
}));
|
|
130
|
+
};
|
|
131
|
+
const reverseShorthandsMapCache = /* @__PURE__ */ new WeakMap();
|
|
132
|
+
const getReverseShorthandsMap = (context) => {
|
|
133
|
+
let reverseMap = reverseShorthandsMapCache.get(context);
|
|
134
|
+
if (!reverseMap) {
|
|
135
|
+
reverseMap = /* @__PURE__ */ new Map();
|
|
136
|
+
const shorthands = context.utility.getPropShorthandsMap();
|
|
137
|
+
for (const [key, values] of shorthands) for (const value of values) reverseMap.set(value, key);
|
|
138
|
+
reverseShorthandsMapCache.set(context, reverseMap);
|
|
139
|
+
}
|
|
140
|
+
return reverseMap;
|
|
141
|
+
};
|
|
142
|
+
const resolveLongHand = (context, name) => {
|
|
143
|
+
return getReverseShorthandsMap(context).get(name);
|
|
144
|
+
};
|
|
145
|
+
const resolveShorthands = (context, name) => {
|
|
146
|
+
return context.utility.getPropShorthandsMap().get(name);
|
|
147
|
+
};
|
|
148
|
+
const getJsxFactory = (context) => {
|
|
149
|
+
return context.config.jsxFactory;
|
|
150
|
+
};
|
|
151
|
+
(0, synckit.runAsWorker)(run);
|
|
152
|
+
//#endregion
|
|
153
|
+
exports.getContext = getContext;
|
|
154
|
+
exports.run = run;
|
|
155
|
+
exports.runAsync = runAsync;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Generator } from "@bamboocss/generator";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/index.d.ts
|
|
4
|
+
type ImportResult = {
|
|
5
|
+
alias: string;
|
|
6
|
+
importMapValue?: string;
|
|
7
|
+
mod: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/utils/worker.d.ts
|
|
12
|
+
type Options = {
|
|
13
|
+
configPath?: string;
|
|
14
|
+
currentFile: string;
|
|
15
|
+
};
|
|
16
|
+
type DeprecatedToken = string | {
|
|
17
|
+
category: string;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
declare function getContext(options: Options): Promise<Generator>;
|
|
21
|
+
type MatchImportResult = {
|
|
22
|
+
alias: string;
|
|
23
|
+
mod: string;
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
declare function run(action: 'filterInvalidTokens', options: Options, paths: string[]): string[];
|
|
27
|
+
declare function run(action: 'isColorToken', options: Options, value: string): boolean;
|
|
28
|
+
declare function run(action: 'isColorAttribute', options: Options, attribute: string): boolean;
|
|
29
|
+
declare function run(action: 'isValidFile', options: Options): boolean;
|
|
30
|
+
declare function run(action: 'resolveShorthands', options: Options, name: string): string[] | undefined;
|
|
31
|
+
declare function run(action: 'resolveLongHand', options: Options, name: string): string | undefined;
|
|
32
|
+
declare function run(action: 'isValidProperty', options: Options, name: string, patternName?: string): boolean;
|
|
33
|
+
declare function run(action: 'matchFile', options: Options, name: string, imports: ImportResult[]): boolean;
|
|
34
|
+
declare function run(action: 'matchImports', options: Options, result: MatchImportResult): boolean;
|
|
35
|
+
declare function run(action: 'filterImports', options: Options, imports: MatchImportResult[]): MatchImportResult[];
|
|
36
|
+
declare function run(action: 'getPropCategory', options: Options, property: string): string;
|
|
37
|
+
declare function run(action: 'filterDeprecatedTokens', options: Options, tokens: DeprecatedToken[]): DeprecatedToken[];
|
|
38
|
+
declare function run(action: 'getJsxFactory', options: Options): string | undefined;
|
|
39
|
+
declare function runAsync(action: 'filterInvalidTokens', options: Options, paths: string[]): Promise<string[]>;
|
|
40
|
+
declare function runAsync(action: 'isColorToken', options: Options, value: string): Promise<boolean>;
|
|
41
|
+
declare function runAsync(action: 'isColorAttribute', options: Options, attribute: string): Promise<boolean>;
|
|
42
|
+
declare function runAsync(action: 'isValidFile', options: Options, fileName: string): Promise<string>;
|
|
43
|
+
declare function runAsync(action: 'resolveShorthands', options: Options, name: string): Promise<string[] | undefined>;
|
|
44
|
+
declare function runAsync(action: 'resolveLongHand', options: Options, name: string): Promise<string | undefined>;
|
|
45
|
+
declare function runAsync(action: 'isValidProperty', options: Options, name: string, patternName?: string): Promise<boolean>;
|
|
46
|
+
declare function runAsync(action: 'matchFile', options: Options, name: string, imports: ImportResult[]): Promise<boolean>;
|
|
47
|
+
declare function runAsync(action: 'matchImports', options: Options, result: MatchImportResult): Promise<boolean>;
|
|
48
|
+
declare function runAsync(action: 'filterImports', options: Options, imports: MatchImportResult[]): Promise<MatchImportResult[]>;
|
|
49
|
+
declare function runAsync(action: 'getPropCategory', options: Options, property: string): Promise<string>;
|
|
50
|
+
declare function runAsync(action: 'filterDeprecatedTokens', options: Options, tokens: DeprecatedToken[]): Promise<DeprecatedToken[]>;
|
|
51
|
+
declare function runAsync(action: 'getJsxFactory', options: Options): Promise<string | undefined>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { DeprecatedToken, getContext, run, runAsync };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
import { Generator } from "@bamboocss/generator";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/index.d.ts
|
|
5
|
+
type ImportResult = {
|
|
6
|
+
alias: string;
|
|
7
|
+
importMapValue?: string;
|
|
8
|
+
mod: string;
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/utils/worker.d.ts
|
|
13
|
+
type Options = {
|
|
14
|
+
configPath?: string;
|
|
15
|
+
currentFile: string;
|
|
16
|
+
};
|
|
17
|
+
type DeprecatedToken = string | {
|
|
18
|
+
category: string;
|
|
19
|
+
value: string;
|
|
20
|
+
};
|
|
21
|
+
declare function getContext(options: Options): Promise<Generator>;
|
|
22
|
+
type MatchImportResult = {
|
|
23
|
+
alias: string;
|
|
24
|
+
mod: string;
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
declare function run(action: 'filterInvalidTokens', options: Options, paths: string[]): string[];
|
|
28
|
+
declare function run(action: 'isColorToken', options: Options, value: string): boolean;
|
|
29
|
+
declare function run(action: 'isColorAttribute', options: Options, attribute: string): boolean;
|
|
30
|
+
declare function run(action: 'isValidFile', options: Options): boolean;
|
|
31
|
+
declare function run(action: 'resolveShorthands', options: Options, name: string): string[] | undefined;
|
|
32
|
+
declare function run(action: 'resolveLongHand', options: Options, name: string): string | undefined;
|
|
33
|
+
declare function run(action: 'isValidProperty', options: Options, name: string, patternName?: string): boolean;
|
|
34
|
+
declare function run(action: 'matchFile', options: Options, name: string, imports: ImportResult[]): boolean;
|
|
35
|
+
declare function run(action: 'matchImports', options: Options, result: MatchImportResult): boolean;
|
|
36
|
+
declare function run(action: 'filterImports', options: Options, imports: MatchImportResult[]): MatchImportResult[];
|
|
37
|
+
declare function run(action: 'getPropCategory', options: Options, property: string): string;
|
|
38
|
+
declare function run(action: 'filterDeprecatedTokens', options: Options, tokens: DeprecatedToken[]): DeprecatedToken[];
|
|
39
|
+
declare function run(action: 'getJsxFactory', options: Options): string | undefined;
|
|
40
|
+
declare function runAsync(action: 'filterInvalidTokens', options: Options, paths: string[]): Promise<string[]>;
|
|
41
|
+
declare function runAsync(action: 'isColorToken', options: Options, value: string): Promise<boolean>;
|
|
42
|
+
declare function runAsync(action: 'isColorAttribute', options: Options, attribute: string): Promise<boolean>;
|
|
43
|
+
declare function runAsync(action: 'isValidFile', options: Options, fileName: string): Promise<string>;
|
|
44
|
+
declare function runAsync(action: 'resolveShorthands', options: Options, name: string): Promise<string[] | undefined>;
|
|
45
|
+
declare function runAsync(action: 'resolveLongHand', options: Options, name: string): Promise<string | undefined>;
|
|
46
|
+
declare function runAsync(action: 'isValidProperty', options: Options, name: string, patternName?: string): Promise<boolean>;
|
|
47
|
+
declare function runAsync(action: 'matchFile', options: Options, name: string, imports: ImportResult[]): Promise<boolean>;
|
|
48
|
+
declare function runAsync(action: 'matchImports', options: Options, result: MatchImportResult): Promise<boolean>;
|
|
49
|
+
declare function runAsync(action: 'filterImports', options: Options, imports: MatchImportResult[]): Promise<MatchImportResult[]>;
|
|
50
|
+
declare function runAsync(action: 'getPropCategory', options: Options, property: string): Promise<string>;
|
|
51
|
+
declare function runAsync(action: 'filterDeprecatedTokens', options: Options, tokens: DeprecatedToken[]): Promise<DeprecatedToken[]>;
|
|
52
|
+
declare function runAsync(action: 'getJsxFactory', options: Options): Promise<string | undefined>;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { DeprecatedToken, getContext, run, runAsync };
|
package/dist/utils/worker.mjs
CHANGED
|
@@ -1,4 +1,135 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { createSyncFn, runAsWorker } from "synckit";
|
|
5
|
+
import { findConfig, loadConfig } from "@bamboocss/config";
|
|
6
|
+
import { resolveTsPathPattern } from "@bamboocss/config/ts-path";
|
|
7
|
+
import { Generator } from "@bamboocss/generator";
|
|
8
|
+
import micromatch from "micromatch";
|
|
9
|
+
import path from "path";
|
|
10
|
+
ESLintUtils.RuleCreator((name) => `https://github.com/bamboocss/bamboo/blob/main/packages/eslint-plugin/docs/rules/${name}.md`);
|
|
11
|
+
const isBase = process.env.NODE_ENV !== "test" || import.meta.url.endsWith("dist/index.js");
|
|
12
|
+
createSyncFn(join(fileURLToPath(new URL(isBase ? "./" : "../../dist", import.meta.url)), "utils/worker.mjs"));
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/utils/worker.ts
|
|
15
|
+
const contextCache = {};
|
|
16
|
+
async function getContext(options) {
|
|
17
|
+
if (process.env.NODE_ENV === "test") {
|
|
18
|
+
const { createGeneratorContext } = await import("../../tests/fixtures/create-context");
|
|
19
|
+
return createGeneratorContext({
|
|
20
|
+
exclude: ["**/Invalid.tsx", "**/bamboo.config.ts"],
|
|
21
|
+
importMap: "./bamboo",
|
|
22
|
+
include: ["**/*"],
|
|
23
|
+
jsxFactory: "styled"
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
const configPath = findConfig({ cwd: options.configPath ?? options.currentFile });
|
|
27
|
+
if (!contextCache[configPath]) contextCache[configPath] = _getContext(configPath);
|
|
28
|
+
return contextCache[configPath];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function _getContext(configPath) {
|
|
32
|
+
if (!configPath) throw new Error("Invalid config path");
|
|
33
|
+
return new Generator(await loadConfig({
|
|
34
|
+
cwd: path.dirname(configPath),
|
|
35
|
+
file: configPath
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
const filterDeprecatedTokens = (context, tokens) => {
|
|
39
|
+
return tokens.filter((token) => {
|
|
40
|
+
const value = typeof token === "string" ? token : token.category + "." + token.value;
|
|
41
|
+
return context.utility.tokens.isDeprecated(value);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const filterInvalidTokens = (context, paths) => {
|
|
45
|
+
return paths.filter((path) => !context.utility.tokens.view.get(path));
|
|
46
|
+
};
|
|
47
|
+
const getPropertyCategory = (context, _attribute) => {
|
|
48
|
+
const attribute = resolveLongHand(context, _attribute) || _attribute;
|
|
49
|
+
const attributeConfig = context.utility.config[attribute];
|
|
50
|
+
return typeof attributeConfig?.values === "string" ? attributeConfig.values : void 0;
|
|
51
|
+
};
|
|
52
|
+
const isColorAttribute = (context, _attribute) => {
|
|
53
|
+
return getPropertyCategory(context, _attribute) === "colors";
|
|
54
|
+
};
|
|
55
|
+
const isColorToken = (context, value) => {
|
|
56
|
+
return Boolean(context.utility.tokens.view.categoryMap.get("colors")?.get(value));
|
|
57
|
+
};
|
|
58
|
+
function run(action, options, ...args) {
|
|
59
|
+
return runAsync(action, options, ...args);
|
|
60
|
+
}
|
|
61
|
+
async function runAsync(action, options, ...args) {
|
|
62
|
+
const context = await getContext(options);
|
|
63
|
+
switch (action) {
|
|
64
|
+
case "filterDeprecatedTokens": return filterDeprecatedTokens(context, ...args);
|
|
65
|
+
case "filterImports": return filterImports(context, ...args);
|
|
66
|
+
case "filterInvalidTokens": return filterInvalidTokens(context, ...args);
|
|
67
|
+
case "getJsxFactory": return getJsxFactory(context);
|
|
68
|
+
case "getPropCategory": return getPropertyCategory(context, ...args);
|
|
69
|
+
case "isColorAttribute": return isColorAttribute(context, ...args);
|
|
70
|
+
case "isColorToken": return isColorToken(context, ...args);
|
|
71
|
+
case "isValidFile": return isValidFile(context, options.currentFile);
|
|
72
|
+
case "isValidProperty": return isValidProperty(context, ...args);
|
|
73
|
+
case "matchFile": return matchFile(context, ...args);
|
|
74
|
+
case "matchImports": return matchImports(context, ...args);
|
|
75
|
+
case "resolveLongHand": return resolveLongHand(context, ...args);
|
|
76
|
+
case "resolveShorthands": return resolveShorthands(context, ...args);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const isValidFile = (context, fileName) => {
|
|
80
|
+
const { exclude, include } = context.config;
|
|
81
|
+
const cwd = context.config.cwd || process.cwd();
|
|
82
|
+
const relativePath = path.isAbsolute(fileName) ? path.relative(cwd, fileName) : fileName;
|
|
83
|
+
return micromatch.isMatch(relativePath, include, {
|
|
84
|
+
dot: true,
|
|
85
|
+
ignore: exclude
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
const isValidProperty = (context, name, patternName) => {
|
|
89
|
+
if (context.isValidProperty(name)) return true;
|
|
90
|
+
if (!patternName) return false;
|
|
91
|
+
if (patternName === context.config.jsxFactory) return false;
|
|
92
|
+
const pattern = context.patterns.details.find((p) => p.baseName === patternName || p.jsx.includes(patternName))?.config.properties;
|
|
93
|
+
if (!pattern) return false;
|
|
94
|
+
return Object.keys(pattern).includes(name);
|
|
95
|
+
};
|
|
96
|
+
const matchFile = (context, name, imports) => {
|
|
97
|
+
return context.imports.file(imports).match(name);
|
|
98
|
+
};
|
|
99
|
+
const matchImports = (context, result) => {
|
|
100
|
+
return context.imports.match(result, (module_) => {
|
|
101
|
+
const { tsOptions } = context.parserOptions;
|
|
102
|
+
if (!tsOptions?.pathMappings) return;
|
|
103
|
+
return resolveTsPathPattern(tsOptions.pathMappings, module_);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const filterImports = (context, imports) => {
|
|
107
|
+
return imports.filter((imp) => context.imports.match(imp, (module_) => {
|
|
108
|
+
const { tsOptions } = context.parserOptions;
|
|
109
|
+
if (!tsOptions?.pathMappings) return;
|
|
110
|
+
return resolveTsPathPattern(tsOptions.pathMappings, module_);
|
|
111
|
+
}));
|
|
112
|
+
};
|
|
113
|
+
const reverseShorthandsMapCache = /* @__PURE__ */ new WeakMap();
|
|
114
|
+
const getReverseShorthandsMap = (context) => {
|
|
115
|
+
let reverseMap = reverseShorthandsMapCache.get(context);
|
|
116
|
+
if (!reverseMap) {
|
|
117
|
+
reverseMap = /* @__PURE__ */ new Map();
|
|
118
|
+
const shorthands = context.utility.getPropShorthandsMap();
|
|
119
|
+
for (const [key, values] of shorthands) for (const value of values) reverseMap.set(value, key);
|
|
120
|
+
reverseShorthandsMapCache.set(context, reverseMap);
|
|
121
|
+
}
|
|
122
|
+
return reverseMap;
|
|
123
|
+
};
|
|
124
|
+
const resolveLongHand = (context, name) => {
|
|
125
|
+
return getReverseShorthandsMap(context).get(name);
|
|
126
|
+
};
|
|
127
|
+
const resolveShorthands = (context, name) => {
|
|
128
|
+
return context.utility.getPropShorthandsMap().get(name);
|
|
129
|
+
};
|
|
130
|
+
const getJsxFactory = (context) => {
|
|
131
|
+
return context.config.jsxFactory;
|
|
132
|
+
};
|
|
133
|
+
runAsWorker(run);
|
|
134
|
+
//#endregion
|
|
135
|
+
export { getContext, run, runAsync };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/eslint-plugin",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.3",
|
|
4
4
|
"description": "ESLint plugin for Bamboo CSS",
|
|
5
5
|
"homepage": "https://bamboo-css.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,18 +13,18 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"sideEffects": false,
|
|
16
|
-
"main": "dist/index.
|
|
16
|
+
"main": "dist/index.cjs",
|
|
17
17
|
"module": "dist/index.mjs",
|
|
18
|
-
"types": "dist/index.d.
|
|
18
|
+
"types": "dist/index.d.cts",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"import": {
|
|
22
|
-
"default": "./dist/index.mjs",
|
|
23
|
-
"types": "./dist/index.d.mts"
|
|
24
|
-
},
|
|
25
|
-
"require": "./dist/index.js",
|
|
26
21
|
"source": "./src/index.ts",
|
|
27
|
-
"types": "./dist/index.d.
|
|
22
|
+
"types": "./dist/index.d.cts",
|
|
23
|
+
"require": "./dist/index.cjs",
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/index.d.mts",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
|
+
}
|
|
28
28
|
},
|
|
29
29
|
"./package.json": "./package.json"
|
|
30
30
|
},
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"@typescript-eslint/utils": "^8.21.0",
|
|
37
37
|
"micromatch": "^4.0.8",
|
|
38
38
|
"synckit": "^0.9.0",
|
|
39
|
-
"@bamboocss/config": "1.12.
|
|
40
|
-
"@bamboocss/generator": "1.12.
|
|
41
|
-
"@bamboocss/shared": "1.12.
|
|
39
|
+
"@bamboocss/config": "1.12.3",
|
|
40
|
+
"@bamboocss/generator": "1.12.3",
|
|
41
|
+
"@bamboocss/shared": "1.12.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/micromatch": "^4.0.10",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"eslint": "^9.35.0",
|
|
47
47
|
"multiline-ts": "^4.0.1",
|
|
48
48
|
"typescript": "^5.7.2",
|
|
49
|
-
"@bamboocss/
|
|
50
|
-
"@bamboocss/
|
|
51
|
-
"@bamboocss/
|
|
52
|
-
"@bamboocss/
|
|
49
|
+
"@bamboocss/preset-bamboo": "1.12.3",
|
|
50
|
+
"@bamboocss/dev": "1.12.3",
|
|
51
|
+
"@bamboocss/preset-base": "1.12.3",
|
|
52
|
+
"@bamboocss/types": "1.12.3"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"eslint": "*"
|