@so1ve/eslint-plugin 0.78.0 → 0.78.2

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 CHANGED
@@ -27,7 +27,7 @@ const functionStyle = createEslintRule({
27
27
  create: (context) => {
28
28
  const sourceCode = context.getSourceCode();
29
29
  const text = sourceCode.getText();
30
- const getStatementRaw = (statement) => text.slice(statement.range[0], statement.range[1]).replace(START_RETURN, "").replace(END_SEMICOLON, "");
30
+ const getStatementRaw = (statement) => `(${text.slice(statement.range[0], statement.range[1]).replace(START_RETURN, "").replace(END_SEMICOLON, "")})`;
31
31
  function getLoneReturnStatement(node) {
32
32
  const { body } = node;
33
33
  if (body.type === types.AST_NODE_TYPES.BlockStatement) {
@@ -40,13 +40,14 @@ const functionStyle = createEslintRule({
40
40
  }
41
41
  }
42
42
  }
43
- function generateFunction(type, name, node, rawStatement) {
43
+ function generateFunction(type, name, node, rawStatement, asVariable = true) {
44
44
  const async = node.async ? "async " : "";
45
45
  const generics = node.typeParameters ? sourceCode.getText(node.typeParameters) : "";
46
46
  const params = node.params.map((param) => sourceCode.getText(param)).join(", ");
47
47
  const returnType = node.returnType ? sourceCode.getText(node.returnType) : "";
48
48
  const body = sourceCode.getText(node.body);
49
- return type === "arrow" ? `const ${name} = ${async}${generics}(${params})${returnType} => ${rawStatement};` : `${async}function ${name}${generics}(${params})${returnType} ${body}`;
49
+ const variableDeclaration = asVariable ? `const ${name} = ` : "";
50
+ return type === "arrow" ? `${variableDeclaration}${async}${generics}(${params})${returnType} => ${rawStatement};` : `${async}function ${name}${generics}(${params})${returnType} ${body}`;
50
51
  }
51
52
  return {
52
53
  FunctionExpression(node) {
@@ -68,6 +69,7 @@ const functionStyle = createEslintRule({
68
69
  if (!statement || !node.id?.name || node.generator) {
69
70
  return;
70
71
  }
72
+ const asVariable = node.parent?.type !== types.AST_NODE_TYPES.ExportDefaultDeclaration;
71
73
  context.report({
72
74
  node,
73
75
  messageId: "arrow",
@@ -77,7 +79,8 @@ const functionStyle = createEslintRule({
77
79
  "arrow",
78
80
  node.id.name,
79
81
  node,
80
- getStatementRaw(statement)
82
+ getStatementRaw(statement),
83
+ asVariable
81
84
  )
82
85
  )
83
86
  });
@@ -94,13 +97,14 @@ const functionStyle = createEslintRule({
94
97
  getStatementRaw(statement)
95
98
  )
96
99
  });
100
+ return;
97
101
  }
98
102
  if (parent?.id?.typeAnnotation) {
99
103
  return;
100
104
  }
101
105
  if (body.type === types.AST_NODE_TYPES.BlockStatement) {
102
106
  const { body: blockBody } = body;
103
- if (blockBody.length > 1 && node.parent?.parent?.type === types.AST_NODE_TYPES.VariableDeclaration) {
107
+ if (blockBody.length > 0 && node.parent?.parent?.type === types.AST_NODE_TYPES.VariableDeclaration) {
104
108
  const { parent: parent2 } = node.parent;
105
109
  context.report({
106
110
  node: parent2,
@@ -244,7 +248,7 @@ const noNegatedEqual = createEslintRule({
244
248
  meta: {
245
249
  type: "problem",
246
250
  docs: {
247
- description: "Disallow negated eqeqeq.",
251
+ description: "Disallow negated equal sign.",
248
252
  recommended: "error"
249
253
  },
250
254
  fixable: "code",
@@ -256,17 +260,18 @@ const noNegatedEqual = createEslintRule({
256
260
  defaultOptions: [],
257
261
  create: (context) => ({
258
262
  BinaryExpression(node) {
259
- const { parent, left, right } = node;
263
+ const { parent, left, right, operator } = node;
260
264
  if (!parent) {
261
265
  return;
262
266
  }
263
- if (["==", "==="].includes(node.operator) && parent.type === types.AST_NODE_TYPES.UnaryExpression && parent.operator === "!") {
267
+ if (["==", "==="].includes(node.operator) && parent.type === types.AST_NODE_TYPES.UnaryExpression && // Is this necessary?
268
+ parent.operator === "!") {
264
269
  context.report({
265
270
  node,
266
271
  messageId: "noNegatedEqual",
267
272
  *fix(fixer) {
268
273
  const operatorRange = [left.range[1], right.range[0]];
269
- const fixedOperator = node.operator === "==" ? "!=" : "!==";
274
+ const fixedOperator = operator === "==" ? "!=" : "!==";
270
275
  yield fixer.replaceTextRange(operatorRange, fixedOperator);
271
276
  yield fixer.removeRange([parent.range[0], parent.range[0] + 1]);
272
277
  }
package/dist/index.mjs CHANGED
@@ -25,7 +25,7 @@ const functionStyle = createEslintRule({
25
25
  create: (context) => {
26
26
  const sourceCode = context.getSourceCode();
27
27
  const text = sourceCode.getText();
28
- const getStatementRaw = (statement) => text.slice(statement.range[0], statement.range[1]).replace(START_RETURN, "").replace(END_SEMICOLON, "");
28
+ const getStatementRaw = (statement) => `(${text.slice(statement.range[0], statement.range[1]).replace(START_RETURN, "").replace(END_SEMICOLON, "")})`;
29
29
  function getLoneReturnStatement(node) {
30
30
  const { body } = node;
31
31
  if (body.type === AST_NODE_TYPES.BlockStatement) {
@@ -38,13 +38,14 @@ const functionStyle = createEslintRule({
38
38
  }
39
39
  }
40
40
  }
41
- function generateFunction(type, name, node, rawStatement) {
41
+ function generateFunction(type, name, node, rawStatement, asVariable = true) {
42
42
  const async = node.async ? "async " : "";
43
43
  const generics = node.typeParameters ? sourceCode.getText(node.typeParameters) : "";
44
44
  const params = node.params.map((param) => sourceCode.getText(param)).join(", ");
45
45
  const returnType = node.returnType ? sourceCode.getText(node.returnType) : "";
46
46
  const body = sourceCode.getText(node.body);
47
- return type === "arrow" ? `const ${name} = ${async}${generics}(${params})${returnType} => ${rawStatement};` : `${async}function ${name}${generics}(${params})${returnType} ${body}`;
47
+ const variableDeclaration = asVariable ? `const ${name} = ` : "";
48
+ return type === "arrow" ? `${variableDeclaration}${async}${generics}(${params})${returnType} => ${rawStatement};` : `${async}function ${name}${generics}(${params})${returnType} ${body}`;
48
49
  }
49
50
  return {
50
51
  FunctionExpression(node) {
@@ -66,6 +67,7 @@ const functionStyle = createEslintRule({
66
67
  if (!statement || !node.id?.name || node.generator) {
67
68
  return;
68
69
  }
70
+ const asVariable = node.parent?.type !== AST_NODE_TYPES.ExportDefaultDeclaration;
69
71
  context.report({
70
72
  node,
71
73
  messageId: "arrow",
@@ -75,7 +77,8 @@ const functionStyle = createEslintRule({
75
77
  "arrow",
76
78
  node.id.name,
77
79
  node,
78
- getStatementRaw(statement)
80
+ getStatementRaw(statement),
81
+ asVariable
79
82
  )
80
83
  )
81
84
  });
@@ -92,13 +95,14 @@ const functionStyle = createEslintRule({
92
95
  getStatementRaw(statement)
93
96
  )
94
97
  });
98
+ return;
95
99
  }
96
100
  if (parent?.id?.typeAnnotation) {
97
101
  return;
98
102
  }
99
103
  if (body.type === AST_NODE_TYPES.BlockStatement) {
100
104
  const { body: blockBody } = body;
101
- if (blockBody.length > 1 && node.parent?.parent?.type === AST_NODE_TYPES.VariableDeclaration) {
105
+ if (blockBody.length > 0 && node.parent?.parent?.type === AST_NODE_TYPES.VariableDeclaration) {
102
106
  const { parent: parent2 } = node.parent;
103
107
  context.report({
104
108
  node: parent2,
@@ -242,7 +246,7 @@ const noNegatedEqual = createEslintRule({
242
246
  meta: {
243
247
  type: "problem",
244
248
  docs: {
245
- description: "Disallow negated eqeqeq.",
249
+ description: "Disallow negated equal sign.",
246
250
  recommended: "error"
247
251
  },
248
252
  fixable: "code",
@@ -254,17 +258,18 @@ const noNegatedEqual = createEslintRule({
254
258
  defaultOptions: [],
255
259
  create: (context) => ({
256
260
  BinaryExpression(node) {
257
- const { parent, left, right } = node;
261
+ const { parent, left, right, operator } = node;
258
262
  if (!parent) {
259
263
  return;
260
264
  }
261
- if (["==", "==="].includes(node.operator) && parent.type === AST_NODE_TYPES.UnaryExpression && parent.operator === "!") {
265
+ if (["==", "==="].includes(node.operator) && parent.type === AST_NODE_TYPES.UnaryExpression && // Is this necessary?
266
+ parent.operator === "!") {
262
267
  context.report({
263
268
  node,
264
269
  messageId: "noNegatedEqual",
265
270
  *fix(fixer) {
266
271
  const operatorRange = [left.range[1], right.range[0]];
267
- const fixedOperator = node.operator === "==" ? "!=" : "!==";
272
+ const fixedOperator = operator === "==" ? "!=" : "!==";
268
273
  yield fixer.replaceTextRange(operatorRange, fixedOperator);
269
274
  yield fixer.removeRange([parent.range[0], parent.range[0] + 1]);
270
275
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-plugin",
3
- "version": "0.78.0",
3
+ "version": "0.78.2",
4
4
  "author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
5
5
  "contributors": [
6
6
  {