@lsby/eslint-plugin 0.0.6 → 0.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
@@ -3,5 +3,6 @@ module.exports = {
3
3
  'no-broken-link': require('./lib/rules/no-broken-link'),
4
4
  'prefer-let': require('./lib/rules/prefer-let'),
5
5
  'no-negation': require('./lib/rules/no-negation'),
6
+ 'no-null': require('./lib/rules/no-null'),
6
7
  },
7
8
  }
@@ -1,39 +1,39 @@
1
1
  module.exports = {
2
2
  meta: {
3
- type: "problem", // 规则类型,可以是 "problem", "suggestion", 或 "layout"
4
- docs: {
5
- description: "Check for broken {@link} references in comments",
6
- category: "Possible Errors",
7
- recommended: false,
8
- },
9
- schema: [], // 规则的选项配置
3
+ type: 'problem', // 规则类型,可以是 "problem", "suggestion", 或 "layout"
4
+ docs: {
5
+ description: 'Check for broken {@link} references in comments',
6
+ category: 'Possible Errors',
7
+ recommended: false,
8
+ },
9
+ schema: [], // 规则的选项配置
10
10
  },
11
- create: function(context) {
12
- return {
13
- Program(node) {
14
- const sourceCode = context.getSourceCode();
15
- const comments = sourceCode.getAllComments();
11
+ create: function (context) {
12
+ return {
13
+ Program(node) {
14
+ const sourceCode = context.getSourceCode()
15
+ const comments = sourceCode.getAllComments()
16
16
 
17
- comments.forEach(comment => {
18
- const matches = comment.value.match(/\{@link\s+([^\s}]+)\s*\}/g);
17
+ comments.forEach((comment) => {
18
+ const matches = comment.value.match(/\{@link\s+([^\s}]+)\s*\}/g)
19
19
 
20
- if (matches) {
21
- matches.forEach(link => {
22
- const identifier = link.match(/\{@link\s+([^\s}]+)\s*\}/)[1];
20
+ if (matches) {
21
+ matches.forEach((link) => {
22
+ const identifier = link.match(/\{@link\s+([^\s}]+)\s*\}/)[1]
23
23
 
24
- const variables = context.getScope().variables;
25
- const isDefined = variables.some(variable => variable.name === identifier);
24
+ const variables = context.getScope().variables
25
+ const isDefined = variables.some((variable) => variable.name === identifier)
26
26
 
27
- if (!isDefined) {
28
- context.report({
29
- node: comment,
30
- message: `The identifier "${identifier}" in {@link} is not defined.`,
31
- });
32
- }
33
- });
34
- }
35
- });
27
+ if (!isDefined) {
28
+ context.report({
29
+ node: comment,
30
+ message: `{@link}中的标识符“${identifier}”没有定义。`,
31
+ })
32
+ }
33
+ })
36
34
  }
37
- };
38
- }
39
- };
35
+ })
36
+ },
37
+ }
38
+ },
39
+ }
@@ -2,10 +2,10 @@ module.exports = {
2
2
  create(context) {
3
3
  return {
4
4
  UnaryExpression(node) {
5
- if (node.operator === '!') {
5
+ if (node.operator === '!' && !(node.argument.type === 'Literal' && typeof node.argument.value === 'boolean')) {
6
6
  context.report({
7
7
  node,
8
- message: "禁止使用 '!' 运算符, 写出更明确的判断条件会减少可能的问题, 如果存在重用逻辑就封装函数.",
8
+ message: "禁止对非布尔值使用 '!' 运算符。",
9
9
  })
10
10
  }
11
11
  },
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: 'suggestion', // 表示这是个建议类型的规则
4
+ docs: {
5
+ description: 'Disallow usage of null and replace it with undefined',
6
+ category: 'Best Practices',
7
+ recommended: false,
8
+ },
9
+ fixable: 'code', // 支持自动修复
10
+ schema: [], // 无额外配置
11
+ },
12
+ create(context) {
13
+ return {
14
+ Literal(node) {
15
+ if (node.value === null) {
16
+ context.report({
17
+ node,
18
+ message: '不允许使用‘null’。使用‘undefined’代替。',
19
+ fix(fixer) {
20
+ return fixer.replaceText(node, 'undefined')
21
+ },
22
+ })
23
+ }
24
+ },
25
+ }
26
+ },
27
+ }
@@ -18,7 +18,7 @@ module.exports = {
18
18
  // 使用修复功能将 const 或 var 替换为 let
19
19
  context.report({
20
20
  node,
21
- message: 'Use let instead of const or var',
21
+ message: '使用let代替constvar',
22
22
  fix(fixer) {
23
23
  // 获取变量声明的范围
24
24
  const range = node.range
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsby/eslint-plugin",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "pub:public": "bumpp && npm publish --access public",