@foundbyte/eslint-plugin 1.0.7 → 1.0.8

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/index.js CHANGED
@@ -4,6 +4,7 @@ const typeCommentRequirementRule = require('./lib/rules/type-comment-requirement
4
4
  const hooksExportLimitRule = require('./lib/rules/hooks-export-limit')
5
5
  const hooksArrowFunctionOnlyRule = require('./lib/rules/hooks-arrow-function-only')
6
6
  const tagAttributeRestrictionRule = require('./lib/rules/tag-attribute-restriction')
7
+ const noInitialAsAssertionRule = require('./lib/rules/no-initial-as-assertion')
7
8
 
8
9
  module.exports = {
9
10
  rules: {
@@ -13,5 +14,6 @@ module.exports = {
13
14
  'hooks-export-limit': hooksExportLimitRule,
14
15
  'hooks-arrow-function-only': hooksArrowFunctionOnlyRule,
15
16
  'tag-attribute-restriction': tagAttributeRestrictionRule,
17
+ 'no-initial-as-assertion': noInitialAsAssertionRule,
16
18
  },
17
19
  }
@@ -4,6 +4,7 @@ export { TypeCommentRequirementOptions } from './type-comment-requirement'
4
4
  export { VueScriptLinesLimitOptions } from './vue-script-lines-limit'
5
5
  export { HooksArrowFunctionOnlyOptions } from './hooks-arrow-function-only'
6
6
  export { TagAttributeRestrictionOptions } from './tag-attribute-restriction'
7
+ export { NoInitialAsAssertionOptions } from './no-initial-as-assertion'
7
8
 
8
9
  import { Rule } from 'eslint'
9
10
 
@@ -41,6 +42,11 @@ export interface Rules {
41
42
  */
42
43
  'tag-attribute-restriction': Rule.RuleModule
43
44
 
45
+ /**
46
+ * 禁止在初始变量定义时使用 as 类型断言
47
+ */
48
+ 'no-initial-as-assertion': Rule.RuleModule
49
+
44
50
  /**
45
51
  * 索引签名,用于兼容 ESLint 插件类型
46
52
  */
@@ -0,0 +1,10 @@
1
+ import { Rule } from 'eslint'
2
+
3
+ export interface NoInitialAsAssertionOptions {}
4
+
5
+ /**
6
+ * 禁止在初始变量定义时使用 as 类型断言
7
+ */
8
+ declare const rule: Rule.RuleModule
9
+
10
+ export default rule
@@ -0,0 +1,46 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: 'suggestion',
4
+ docs: {
5
+ description: '禁止在初始变量定义时使用 as 类型断言',
6
+ category: 'Best Practices',
7
+ recommended: false,
8
+ },
9
+ fixable: null,
10
+ schema: [],
11
+ messages: {
12
+ noInitialAsAssertion: '禁止在初始变量定义时使用 as 类型断言,请使用显式类型注解',
13
+ },
14
+ },
15
+
16
+ create(context) {
17
+ /**
18
+ * 检查变量声明是否使用了 as 类型断言
19
+ * @param {Object} node AST节点
20
+ */
21
+ function checkVariableDeclaration(node) {
22
+ // 只检查变量声明
23
+ if (node.type !== 'VariableDeclaration') {
24
+ return;
25
+ }
26
+
27
+ // 遍历所有声明
28
+ node.declarations.forEach(declaration => {
29
+ // 检查是否有初始化表达式
30
+ if (declaration.init) {
31
+ // 检查初始化表达式是否是类型断言表达式
32
+ if (declaration.init.type === 'TSAsExpression') {
33
+ context.report({
34
+ node: declaration,
35
+ messageId: 'noInitialAsAssertion',
36
+ });
37
+ }
38
+ }
39
+ });
40
+ }
41
+
42
+ return {
43
+ VariableDeclaration: checkVariableDeclaration,
44
+ };
45
+ },
46
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foundbyte/eslint-plugin",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "ESLint plugin for enforcing code style rules including arrow function padding, Vue script lines limit, and TypeScript type comment requirements",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",