@wsxjs/eslint-plugin-wsx 0.0.5
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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/chunk-MR6HKTAK.mjs +105 -0
- package/dist/configs/flat.js +130 -0
- package/dist/configs/flat.mjs +8 -0
- package/dist/index.d.mts +48 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +387 -0
- package/dist/index.mjs +358 -0
- package/package.json +55 -0
- package/src/configs/flat.ts +105 -0
- package/src/configs/recommended.ts +90 -0
- package/src/index.ts +46 -0
- package/src/rules/no-react-imports.ts +55 -0
- package/src/rules/render-method-required.ts +55 -0
- package/src/rules/web-component-naming.ts +97 -0
- package/src/types.ts +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 WSX Framework Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @systembug/wsx-eslint-plugin
|
|
2
|
+
|
|
3
|
+
ESLint plugin for WSX Framework - enforces best practices and framework-specific rules for Web Components with JSX.
|
|
4
|
+
|
|
5
|
+
## Testing Results
|
|
6
|
+
|
|
7
|
+
✅ **38 tests passed** with **100% code coverage**
|
|
8
|
+
✅ **Professional test suite** using Jest and ESLint RuleTester
|
|
9
|
+
✅ **Integration tests** verify real-world usage scenarios
|
|
10
|
+
|
|
11
|
+
## Test Coverage Summary
|
|
12
|
+
- **Statements**: 100%
|
|
13
|
+
- **Branches**: 96.96%
|
|
14
|
+
- **Functions**: 100%
|
|
15
|
+
- **Lines**: 100%
|
|
16
|
+
|
|
17
|
+
## Better Testing Approach
|
|
18
|
+
|
|
19
|
+
This plugin now uses industry-standard testing practices:
|
|
20
|
+
|
|
21
|
+
### 1. Unit Tests with RuleTester
|
|
22
|
+
- Each rule has dedicated test files
|
|
23
|
+
- Valid/invalid code examples with expected errors
|
|
24
|
+
- Proper AST node testing
|
|
25
|
+
|
|
26
|
+
### 2. Integration Tests
|
|
27
|
+
- Full plugin functionality testing
|
|
28
|
+
- Real ESLint configuration scenarios
|
|
29
|
+
- Complex component examples
|
|
30
|
+
|
|
31
|
+
### 3. Comprehensive Coverage
|
|
32
|
+
- All rules tested with edge cases
|
|
33
|
+
- Error messages and fix suggestions verified
|
|
34
|
+
- Plugin structure and exports validated
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- 🔍 **render-method-required**: Ensures WSX components implement the required `render()` method
|
|
39
|
+
- 🚫 **no-react-imports**: Prevents React imports in WSX files
|
|
40
|
+
- 🏷️ **web-component-naming**: Enforces proper Web Component tag naming conventions
|
|
41
|
+
|
|
42
|
+
## Framework Integration
|
|
43
|
+
|
|
44
|
+
The examples package serves as a **real-world testing environment** where:
|
|
45
|
+
1. The ESLint plugin is properly configured and tested
|
|
46
|
+
2. All WSX components demonstrate correct framework usage
|
|
47
|
+
3. Plugin rules catch actual coding errors in development
|
|
48
|
+
4. Framework developers can validate plugin effectiveness
|
|
49
|
+
|
|
50
|
+
This approach ensures the plugin works correctly in production environments, not just in isolated tests.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// src/configs/flat.ts
|
|
2
|
+
var flatConfig = {
|
|
3
|
+
name: "wsx/recommended",
|
|
4
|
+
files: ["**/*.tsx", "**/*.jsx", "**/*.wsx"],
|
|
5
|
+
languageOptions: {
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
ecmaVersion: "latest",
|
|
8
|
+
sourceType: "module",
|
|
9
|
+
parserOptions: {
|
|
10
|
+
ecmaFeatures: {
|
|
11
|
+
jsx: true
|
|
12
|
+
},
|
|
13
|
+
jsxPragma: "h",
|
|
14
|
+
jsxFragmentName: "Fragment",
|
|
15
|
+
extraFileExtensions: [".wsx"]
|
|
16
|
+
},
|
|
17
|
+
globals: {
|
|
18
|
+
// Browser environment
|
|
19
|
+
window: "readonly",
|
|
20
|
+
document: "readonly",
|
|
21
|
+
console: "readonly",
|
|
22
|
+
// Node.js environment
|
|
23
|
+
process: "readonly",
|
|
24
|
+
Buffer: "readonly",
|
|
25
|
+
__dirname: "readonly",
|
|
26
|
+
__filename: "readonly",
|
|
27
|
+
global: "readonly",
|
|
28
|
+
module: "readonly",
|
|
29
|
+
require: "readonly",
|
|
30
|
+
exports: "readonly",
|
|
31
|
+
// Web Components API
|
|
32
|
+
HTMLElement: "readonly",
|
|
33
|
+
customElements: "readonly",
|
|
34
|
+
CustomEvent: "readonly",
|
|
35
|
+
ShadowRoot: "readonly",
|
|
36
|
+
HTMLSlotElement: "readonly",
|
|
37
|
+
CSSStyleSheet: "readonly",
|
|
38
|
+
// WSX specific
|
|
39
|
+
h: "readonly",
|
|
40
|
+
Fragment: "readonly"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
plugins: {
|
|
44
|
+
wsx: {
|
|
45
|
+
rules: {
|
|
46
|
+
"render-method-required": {},
|
|
47
|
+
"no-react-imports": {},
|
|
48
|
+
"web-component-naming": {}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
rules: {
|
|
53
|
+
// WSX specific rules
|
|
54
|
+
"wsx/render-method-required": "error",
|
|
55
|
+
"wsx/no-react-imports": "error",
|
|
56
|
+
"wsx/web-component-naming": "warn",
|
|
57
|
+
// TypeScript rules (recommended)
|
|
58
|
+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
|
|
59
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
60
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
61
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
62
|
+
"@typescript-eslint/no-non-null-assertion": "warn",
|
|
63
|
+
// General rules
|
|
64
|
+
"no-console": ["warn", { allow: ["warn", "error"] }],
|
|
65
|
+
"no-debugger": "error",
|
|
66
|
+
"no-unused-vars": "off",
|
|
67
|
+
// Use TypeScript version
|
|
68
|
+
"no-undef": "off",
|
|
69
|
+
// TypeScript handles this
|
|
70
|
+
"prefer-const": "error",
|
|
71
|
+
"no-var": "error",
|
|
72
|
+
"no-duplicate-imports": "error",
|
|
73
|
+
"no-trailing-spaces": "error",
|
|
74
|
+
"eol-last": "error",
|
|
75
|
+
"comma-dangle": ["error", "always-multiline"],
|
|
76
|
+
semi: ["error", "always"],
|
|
77
|
+
quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
|
|
78
|
+
// 明确禁用所有 React 相关规则
|
|
79
|
+
"react/react-in-jsx-scope": "off",
|
|
80
|
+
"react/prop-types": "off",
|
|
81
|
+
"react/jsx-uses-react": "off",
|
|
82
|
+
"react/jsx-uses-vars": "off",
|
|
83
|
+
"react/jsx-key": "off",
|
|
84
|
+
"react/jsx-no-duplicate-props": "off",
|
|
85
|
+
"react/jsx-no-undef": "off",
|
|
86
|
+
"react/no-array-index-key": "off",
|
|
87
|
+
"react/no-unescaped-entities": "off"
|
|
88
|
+
},
|
|
89
|
+
settings: {
|
|
90
|
+
// No React settings needed
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
function createFlatConfig(plugin) {
|
|
94
|
+
return {
|
|
95
|
+
...flatConfig,
|
|
96
|
+
plugins: {
|
|
97
|
+
wsx: plugin
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
flatConfig,
|
|
104
|
+
createFlatConfig
|
|
105
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/configs/flat.ts
|
|
21
|
+
var flat_exports = {};
|
|
22
|
+
__export(flat_exports, {
|
|
23
|
+
createFlatConfig: () => createFlatConfig,
|
|
24
|
+
flatConfig: () => flatConfig
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(flat_exports);
|
|
27
|
+
var flatConfig = {
|
|
28
|
+
name: "wsx/recommended",
|
|
29
|
+
files: ["**/*.tsx", "**/*.jsx", "**/*.wsx"],
|
|
30
|
+
languageOptions: {
|
|
31
|
+
parser: "@typescript-eslint/parser",
|
|
32
|
+
ecmaVersion: "latest",
|
|
33
|
+
sourceType: "module",
|
|
34
|
+
parserOptions: {
|
|
35
|
+
ecmaFeatures: {
|
|
36
|
+
jsx: true
|
|
37
|
+
},
|
|
38
|
+
jsxPragma: "h",
|
|
39
|
+
jsxFragmentName: "Fragment",
|
|
40
|
+
extraFileExtensions: [".wsx"]
|
|
41
|
+
},
|
|
42
|
+
globals: {
|
|
43
|
+
// Browser environment
|
|
44
|
+
window: "readonly",
|
|
45
|
+
document: "readonly",
|
|
46
|
+
console: "readonly",
|
|
47
|
+
// Node.js environment
|
|
48
|
+
process: "readonly",
|
|
49
|
+
Buffer: "readonly",
|
|
50
|
+
__dirname: "readonly",
|
|
51
|
+
__filename: "readonly",
|
|
52
|
+
global: "readonly",
|
|
53
|
+
module: "readonly",
|
|
54
|
+
require: "readonly",
|
|
55
|
+
exports: "readonly",
|
|
56
|
+
// Web Components API
|
|
57
|
+
HTMLElement: "readonly",
|
|
58
|
+
customElements: "readonly",
|
|
59
|
+
CustomEvent: "readonly",
|
|
60
|
+
ShadowRoot: "readonly",
|
|
61
|
+
HTMLSlotElement: "readonly",
|
|
62
|
+
CSSStyleSheet: "readonly",
|
|
63
|
+
// WSX specific
|
|
64
|
+
h: "readonly",
|
|
65
|
+
Fragment: "readonly"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
plugins: {
|
|
69
|
+
wsx: {
|
|
70
|
+
rules: {
|
|
71
|
+
"render-method-required": {},
|
|
72
|
+
"no-react-imports": {},
|
|
73
|
+
"web-component-naming": {}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
rules: {
|
|
78
|
+
// WSX specific rules
|
|
79
|
+
"wsx/render-method-required": "error",
|
|
80
|
+
"wsx/no-react-imports": "error",
|
|
81
|
+
"wsx/web-component-naming": "warn",
|
|
82
|
+
// TypeScript rules (recommended)
|
|
83
|
+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
|
|
84
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
85
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
86
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
87
|
+
"@typescript-eslint/no-non-null-assertion": "warn",
|
|
88
|
+
// General rules
|
|
89
|
+
"no-console": ["warn", { allow: ["warn", "error"] }],
|
|
90
|
+
"no-debugger": "error",
|
|
91
|
+
"no-unused-vars": "off",
|
|
92
|
+
// Use TypeScript version
|
|
93
|
+
"no-undef": "off",
|
|
94
|
+
// TypeScript handles this
|
|
95
|
+
"prefer-const": "error",
|
|
96
|
+
"no-var": "error",
|
|
97
|
+
"no-duplicate-imports": "error",
|
|
98
|
+
"no-trailing-spaces": "error",
|
|
99
|
+
"eol-last": "error",
|
|
100
|
+
"comma-dangle": ["error", "always-multiline"],
|
|
101
|
+
semi: ["error", "always"],
|
|
102
|
+
quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
|
|
103
|
+
// 明确禁用所有 React 相关规则
|
|
104
|
+
"react/react-in-jsx-scope": "off",
|
|
105
|
+
"react/prop-types": "off",
|
|
106
|
+
"react/jsx-uses-react": "off",
|
|
107
|
+
"react/jsx-uses-vars": "off",
|
|
108
|
+
"react/jsx-key": "off",
|
|
109
|
+
"react/jsx-no-duplicate-props": "off",
|
|
110
|
+
"react/jsx-no-undef": "off",
|
|
111
|
+
"react/no-array-index-key": "off",
|
|
112
|
+
"react/no-unescaped-entities": "off"
|
|
113
|
+
},
|
|
114
|
+
settings: {
|
|
115
|
+
// No React settings needed
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
function createFlatConfig(plugin) {
|
|
119
|
+
return {
|
|
120
|
+
...flatConfig,
|
|
121
|
+
plugins: {
|
|
122
|
+
wsx: plugin
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
127
|
+
0 && (module.exports = {
|
|
128
|
+
createFlatConfig,
|
|
129
|
+
flatConfig
|
|
130
|
+
});
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as eslint from 'eslint';
|
|
2
|
+
import { Rule } from 'eslint';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TypeScript 类型定义 - WSX ESLint 插件
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface WSXRuleContext extends Rule.RuleContext {
|
|
9
|
+
report: (descriptor: Rule.ReportDescriptor) => void;
|
|
10
|
+
}
|
|
11
|
+
interface WSXRuleModule extends Rule.RuleModule {
|
|
12
|
+
create: (context: WSXRuleContext) => Rule.RuleListener;
|
|
13
|
+
}
|
|
14
|
+
interface WSXConfig {
|
|
15
|
+
parser?: string;
|
|
16
|
+
parserOptions?: {
|
|
17
|
+
ecmaVersion?: string | number;
|
|
18
|
+
sourceType?: "script" | "module";
|
|
19
|
+
ecmaFeatures?: {
|
|
20
|
+
jsx?: boolean;
|
|
21
|
+
};
|
|
22
|
+
jsxPragma?: string;
|
|
23
|
+
jsxFragmentName?: string;
|
|
24
|
+
};
|
|
25
|
+
plugins?: string[];
|
|
26
|
+
rules?: Record<string, unknown>;
|
|
27
|
+
globals?: Record<string, "readonly" | "writable">;
|
|
28
|
+
settings?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
interface WSXPluginMeta {
|
|
31
|
+
name: string;
|
|
32
|
+
version: string;
|
|
33
|
+
}
|
|
34
|
+
interface WSXPlugin {
|
|
35
|
+
meta: WSXPluginMeta;
|
|
36
|
+
rules: Record<string, WSXRuleModule>;
|
|
37
|
+
configs: Record<string, WSXConfig>;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare const plugin: WSXPlugin;
|
|
42
|
+
declare const flat: {
|
|
43
|
+
recommended: eslint.Linter.FlatConfig<eslint.Linter.RulesRecord>;
|
|
44
|
+
};
|
|
45
|
+
declare const rules: Record<string, WSXRuleModule>;
|
|
46
|
+
declare const configs: Record<string, WSXConfig>;
|
|
47
|
+
|
|
48
|
+
export { configs, plugin as default, flat, rules };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as eslint from 'eslint';
|
|
2
|
+
import { Rule } from 'eslint';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TypeScript 类型定义 - WSX ESLint 插件
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface WSXRuleContext extends Rule.RuleContext {
|
|
9
|
+
report: (descriptor: Rule.ReportDescriptor) => void;
|
|
10
|
+
}
|
|
11
|
+
interface WSXRuleModule extends Rule.RuleModule {
|
|
12
|
+
create: (context: WSXRuleContext) => Rule.RuleListener;
|
|
13
|
+
}
|
|
14
|
+
interface WSXConfig {
|
|
15
|
+
parser?: string;
|
|
16
|
+
parserOptions?: {
|
|
17
|
+
ecmaVersion?: string | number;
|
|
18
|
+
sourceType?: "script" | "module";
|
|
19
|
+
ecmaFeatures?: {
|
|
20
|
+
jsx?: boolean;
|
|
21
|
+
};
|
|
22
|
+
jsxPragma?: string;
|
|
23
|
+
jsxFragmentName?: string;
|
|
24
|
+
};
|
|
25
|
+
plugins?: string[];
|
|
26
|
+
rules?: Record<string, unknown>;
|
|
27
|
+
globals?: Record<string, "readonly" | "writable">;
|
|
28
|
+
settings?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
interface WSXPluginMeta {
|
|
31
|
+
name: string;
|
|
32
|
+
version: string;
|
|
33
|
+
}
|
|
34
|
+
interface WSXPlugin {
|
|
35
|
+
meta: WSXPluginMeta;
|
|
36
|
+
rules: Record<string, WSXRuleModule>;
|
|
37
|
+
configs: Record<string, WSXConfig>;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare const plugin: WSXPlugin;
|
|
42
|
+
declare const flat: {
|
|
43
|
+
recommended: eslint.Linter.FlatConfig<eslint.Linter.RulesRecord>;
|
|
44
|
+
};
|
|
45
|
+
declare const rules: Record<string, WSXRuleModule>;
|
|
46
|
+
declare const configs: Record<string, WSXConfig>;
|
|
47
|
+
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
export = plugin;
|
|
50
|
+
export { configs, flat, rules };
|