eslint 8.47.0 → 8.57.0
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/README.md +18 -13
- package/bin/eslint.js +38 -5
- package/conf/rule-type-list.json +25 -33
- package/lib/api.js +29 -1
- package/lib/cli-engine/cli-engine.js +2 -2
- package/lib/cli-engine/lint-result-cache.js +18 -6
- package/lib/cli.js +36 -6
- package/lib/config/flat-config-schema.js +124 -61
- package/lib/config/rule-validator.js +2 -1
- package/lib/eslint/eslint-helpers.js +9 -11
- package/lib/eslint/eslint.js +7 -0
- package/lib/eslint/flat-eslint.js +33 -18
- package/lib/linter/apply-disable-directives.js +127 -13
- package/lib/linter/code-path-analysis/code-path-analyzer.js +32 -24
- package/lib/linter/code-path-analysis/code-path-segment.js +52 -24
- package/lib/linter/code-path-analysis/code-path-state.js +1108 -243
- package/lib/linter/code-path-analysis/code-path.js +128 -33
- package/lib/linter/code-path-analysis/fork-context.js +173 -72
- package/lib/linter/config-comment-parser.js +36 -2
- package/lib/linter/linter.js +183 -82
- package/lib/options.js +24 -3
- package/lib/rule-tester/flat-rule-tester.js +113 -25
- package/lib/rule-tester/rule-tester.js +176 -23
- package/lib/rules/array-bracket-newline.js +3 -0
- package/lib/rules/array-bracket-spacing.js +3 -0
- package/lib/rules/array-callback-return.js +175 -25
- package/lib/rules/array-element-newline.js +3 -0
- package/lib/rules/arrow-parens.js +3 -0
- package/lib/rules/arrow-spacing.js +3 -0
- package/lib/rules/block-spacing.js +3 -0
- package/lib/rules/brace-style.js +3 -0
- package/lib/rules/comma-dangle.js +3 -0
- package/lib/rules/comma-spacing.js +3 -0
- package/lib/rules/comma-style.js +3 -0
- package/lib/rules/computed-property-spacing.js +3 -0
- package/lib/rules/consistent-return.js +32 -7
- package/lib/rules/constructor-super.js +37 -14
- package/lib/rules/dot-location.js +3 -0
- package/lib/rules/eol-last.js +3 -0
- package/lib/rules/for-direction.js +38 -24
- package/lib/rules/func-call-spacing.js +3 -0
- package/lib/rules/function-call-argument-newline.js +3 -0
- package/lib/rules/function-paren-newline.js +3 -0
- package/lib/rules/generator-star-spacing.js +3 -0
- package/lib/rules/getter-return.js +33 -8
- package/lib/rules/implicit-arrow-linebreak.js +3 -0
- package/lib/rules/indent.js +3 -0
- package/lib/rules/index.js +1 -0
- package/lib/rules/jsx-quotes.js +3 -0
- package/lib/rules/key-spacing.js +3 -0
- package/lib/rules/keyword-spacing.js +3 -0
- package/lib/rules/linebreak-style.js +3 -0
- package/lib/rules/lines-around-comment.js +3 -0
- package/lib/rules/lines-between-class-members.js +95 -7
- package/lib/rules/logical-assignment-operators.js +31 -3
- package/lib/rules/max-len.js +3 -0
- package/lib/rules/max-statements-per-line.js +3 -0
- package/lib/rules/multiline-ternary.js +3 -0
- package/lib/rules/new-parens.js +3 -0
- package/lib/rules/newline-per-chained-call.js +3 -0
- package/lib/rules/no-array-constructor.js +85 -6
- package/lib/rules/no-confusing-arrow.js +3 -0
- package/lib/rules/no-console.js +74 -2
- package/lib/rules/no-extra-parens.js +3 -0
- package/lib/rules/no-extra-semi.js +3 -0
- package/lib/rules/no-fallthrough.js +42 -14
- package/lib/rules/no-floating-decimal.js +3 -0
- package/lib/rules/no-invalid-this.js +1 -1
- package/lib/rules/no-misleading-character-class.js +65 -15
- package/lib/rules/no-mixed-operators.js +3 -0
- package/lib/rules/no-mixed-spaces-and-tabs.js +3 -0
- package/lib/rules/no-multi-spaces.js +3 -0
- package/lib/rules/no-multiple-empty-lines.js +3 -0
- package/lib/rules/no-new-object.js +7 -0
- package/lib/rules/no-object-constructor.js +117 -0
- package/lib/rules/no-promise-executor-return.js +157 -16
- package/lib/rules/no-prototype-builtins.js +90 -2
- package/lib/rules/no-restricted-imports.js +54 -31
- package/lib/rules/no-restricted-properties.js +15 -28
- package/lib/rules/no-tabs.js +3 -0
- package/lib/rules/no-this-before-super.js +38 -11
- package/lib/rules/no-trailing-spaces.js +3 -0
- package/lib/rules/no-unreachable-loop.js +47 -12
- package/lib/rules/no-unreachable.js +39 -10
- package/lib/rules/no-useless-return.js +35 -4
- package/lib/rules/no-whitespace-before-property.js +3 -0
- package/lib/rules/nonblock-statement-body-position.js +3 -0
- package/lib/rules/object-curly-newline.js +3 -0
- package/lib/rules/object-curly-spacing.js +3 -0
- package/lib/rules/object-property-newline.js +3 -0
- package/lib/rules/one-var-declaration-per-line.js +3 -0
- package/lib/rules/operator-linebreak.js +3 -0
- package/lib/rules/padded-blocks.js +3 -0
- package/lib/rules/padding-line-between-statements.js +3 -0
- package/lib/rules/quote-props.js +3 -0
- package/lib/rules/quotes.js +3 -0
- package/lib/rules/require-atomic-updates.js +21 -7
- package/lib/rules/rest-spread-spacing.js +3 -0
- package/lib/rules/semi-spacing.js +3 -0
- package/lib/rules/semi-style.js +3 -0
- package/lib/rules/semi.js +3 -0
- package/lib/rules/space-before-blocks.js +3 -0
- package/lib/rules/space-before-function-paren.js +3 -0
- package/lib/rules/space-in-parens.js +3 -0
- package/lib/rules/space-infix-ops.js +3 -0
- package/lib/rules/space-unary-ops.js +3 -0
- package/lib/rules/spaced-comment.js +3 -0
- package/lib/rules/switch-colon-spacing.js +3 -0
- package/lib/rules/template-curly-spacing.js +3 -0
- package/lib/rules/template-tag-spacing.js +3 -0
- package/lib/rules/utils/ast-utils.js +111 -1
- package/lib/rules/wrap-iife.js +3 -0
- package/lib/rules/wrap-regex.js +3 -0
- package/lib/rules/yield-star-spacing.js +3 -0
- package/lib/shared/severity.js +49 -0
- package/lib/source-code/source-code.js +329 -3
- package/messages/eslintrc-incompat.js +1 -1
- package/package.json +24 -17
package/lib/rules/semi-style.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to enforce location of semicolons.
|
3
3
|
* @author Toru Nagashima
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -70,6 +71,8 @@ function isLastChild(node) {
|
|
70
71
|
/** @type {import('../shared/types').Rule} */
|
71
72
|
module.exports = {
|
72
73
|
meta: {
|
74
|
+
deprecated: true,
|
75
|
+
replacedBy: [],
|
73
76
|
type: "layout",
|
74
77
|
|
75
78
|
docs: {
|
package/lib/rules/semi.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to flag missing semicolons.
|
3
3
|
* @author Nicholas C. Zakas
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
"use strict";
|
6
7
|
|
@@ -18,6 +19,8 @@ const astUtils = require("./utils/ast-utils");
|
|
18
19
|
/** @type {import('../shared/types').Rule} */
|
19
20
|
module.exports = {
|
20
21
|
meta: {
|
22
|
+
deprecated: true,
|
23
|
+
replacedBy: [],
|
21
24
|
type: "layout",
|
22
25
|
|
23
26
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview A rule to ensure whitespace before blocks.
|
3
3
|
* @author Mathias Schreck <https://github.com/lo1tuma>
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -37,6 +38,8 @@ function isFunctionBody(node) {
|
|
37
38
|
/** @type {import('../shared/types').Rule} */
|
38
39
|
module.exports = {
|
39
40
|
meta: {
|
41
|
+
deprecated: true,
|
42
|
+
replacedBy: [],
|
40
43
|
type: "layout",
|
41
44
|
|
42
45
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to validate spacing before function paren.
|
3
3
|
* @author Mathias Schreck <https://github.com/lo1tuma>
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
"use strict";
|
6
7
|
|
@@ -17,6 +18,8 @@ const astUtils = require("./utils/ast-utils");
|
|
17
18
|
/** @type {import('../shared/types').Rule} */
|
18
19
|
module.exports = {
|
19
20
|
meta: {
|
21
|
+
deprecated: true,
|
22
|
+
replacedBy: [],
|
20
23
|
type: "layout",
|
21
24
|
|
22
25
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Disallows or enforces spaces inside of parentheses.
|
3
3
|
* @author Jonathan Rajavuori
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
"use strict";
|
6
7
|
|
@@ -13,6 +14,8 @@ const astUtils = require("./utils/ast-utils");
|
|
13
14
|
/** @type {import('../shared/types').Rule} */
|
14
15
|
module.exports = {
|
15
16
|
meta: {
|
17
|
+
deprecated: true,
|
18
|
+
replacedBy: [],
|
16
19
|
type: "layout",
|
17
20
|
|
18
21
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Require spaces around infix operators
|
3
3
|
* @author Michael Ficarra
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
"use strict";
|
6
7
|
|
@@ -13,6 +14,8 @@ const { isEqToken } = require("./utils/ast-utils");
|
|
13
14
|
/** @type {import('../shared/types').Rule} */
|
14
15
|
module.exports = {
|
15
16
|
meta: {
|
17
|
+
deprecated: true,
|
18
|
+
replacedBy: [],
|
16
19
|
type: "layout",
|
17
20
|
|
18
21
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview This rule should require or disallow spaces before or after unary operations.
|
3
3
|
* @author Marcin Kumorek
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
"use strict";
|
6
7
|
|
@@ -17,6 +18,8 @@ const astUtils = require("./utils/ast-utils");
|
|
17
18
|
/** @type {import('../shared/types').Rule} */
|
18
19
|
module.exports = {
|
19
20
|
meta: {
|
21
|
+
deprecated: true,
|
22
|
+
replacedBy: [],
|
20
23
|
type: "layout",
|
21
24
|
|
22
25
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Source code for spaced-comments rule
|
3
3
|
* @author Gyandeep Singh
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
"use strict";
|
6
7
|
|
@@ -149,6 +150,8 @@ function createNeverStylePattern(markers) {
|
|
149
150
|
/** @type {import('../shared/types').Rule} */
|
150
151
|
module.exports = {
|
151
152
|
meta: {
|
153
|
+
deprecated: true,
|
154
|
+
replacedBy: [],
|
152
155
|
type: "suggestion",
|
153
156
|
|
154
157
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to enforce spacing around colons of switch statements.
|
3
3
|
* @author Toru Nagashima
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -18,6 +19,8 @@ const astUtils = require("./utils/ast-utils");
|
|
18
19
|
/** @type {import('../shared/types').Rule} */
|
19
20
|
module.exports = {
|
20
21
|
meta: {
|
22
|
+
deprecated: true,
|
23
|
+
replacedBy: [],
|
21
24
|
type: "layout",
|
22
25
|
|
23
26
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to enforce spacing around embedded expressions of template strings
|
3
3
|
* @author Toru Nagashima
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -18,6 +19,8 @@ const astUtils = require("./utils/ast-utils");
|
|
18
19
|
/** @type {import('../shared/types').Rule} */
|
19
20
|
module.exports = {
|
20
21
|
meta: {
|
22
|
+
deprecated: true,
|
23
|
+
replacedBy: [],
|
21
24
|
type: "layout",
|
22
25
|
|
23
26
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to check spacing between template tags and their literals
|
3
3
|
* @author Jonathan Wilsson
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -12,6 +13,8 @@
|
|
12
13
|
/** @type {import('../shared/types').Rule} */
|
13
14
|
module.exports = {
|
14
15
|
meta: {
|
16
|
+
deprecated: true,
|
17
|
+
replacedBy: [],
|
15
18
|
type: "layout",
|
16
19
|
|
17
20
|
docs: {
|
@@ -1015,6 +1015,114 @@ function isDirective(node) {
|
|
1015
1015
|
return node.type === "ExpressionStatement" && typeof node.directive === "string";
|
1016
1016
|
}
|
1017
1017
|
|
1018
|
+
/**
|
1019
|
+
* Tests if a node appears at the beginning of an ancestor ExpressionStatement node.
|
1020
|
+
* @param {ASTNode} node The node to check.
|
1021
|
+
* @returns {boolean} Whether the node appears at the beginning of an ancestor ExpressionStatement node.
|
1022
|
+
*/
|
1023
|
+
function isStartOfExpressionStatement(node) {
|
1024
|
+
const start = node.range[0];
|
1025
|
+
let ancestor = node;
|
1026
|
+
|
1027
|
+
while ((ancestor = ancestor.parent) && ancestor.range[0] === start) {
|
1028
|
+
if (ancestor.type === "ExpressionStatement") {
|
1029
|
+
return true;
|
1030
|
+
}
|
1031
|
+
}
|
1032
|
+
return false;
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
/**
|
1036
|
+
* Determines whether an opening parenthesis `(`, bracket `[` or backtick ``` ` ``` needs to be preceded by a semicolon.
|
1037
|
+
* This opening parenthesis or bracket should be at the start of an `ExpressionStatement` or at the start of the body of an `ArrowFunctionExpression`.
|
1038
|
+
* @type {(sourceCode: SourceCode, node: ASTNode) => boolean}
|
1039
|
+
* @param {SourceCode} sourceCode The source code object.
|
1040
|
+
* @param {ASTNode} node A node at the position where an opening parenthesis or bracket will be inserted.
|
1041
|
+
* @returns {boolean} Whether a semicolon is required before the opening parenthesis or braket.
|
1042
|
+
*/
|
1043
|
+
let needsPrecedingSemicolon;
|
1044
|
+
|
1045
|
+
{
|
1046
|
+
const BREAK_OR_CONTINUE = new Set(["BreakStatement", "ContinueStatement"]);
|
1047
|
+
|
1048
|
+
// Declaration types that must contain a string Literal node at the end.
|
1049
|
+
const DECLARATIONS = new Set(["ExportAllDeclaration", "ExportNamedDeclaration", "ImportDeclaration"]);
|
1050
|
+
|
1051
|
+
const IDENTIFIER_OR_KEYWORD = new Set(["Identifier", "Keyword"]);
|
1052
|
+
|
1053
|
+
// Keywords that can immediately precede an ExpressionStatement node, mapped to the their node types.
|
1054
|
+
const NODE_TYPES_BY_KEYWORD = {
|
1055
|
+
__proto__: null,
|
1056
|
+
break: "BreakStatement",
|
1057
|
+
continue: "ContinueStatement",
|
1058
|
+
debugger: "DebuggerStatement",
|
1059
|
+
do: "DoWhileStatement",
|
1060
|
+
else: "IfStatement",
|
1061
|
+
return: "ReturnStatement",
|
1062
|
+
yield: "YieldExpression"
|
1063
|
+
};
|
1064
|
+
|
1065
|
+
/*
|
1066
|
+
* Before an opening parenthesis, postfix `++` and `--` always trigger ASI;
|
1067
|
+
* the tokens `:`, `;`, `{` and `=>` don't expect a semicolon, as that would count as an empty statement.
|
1068
|
+
*/
|
1069
|
+
const PUNCTUATORS = new Set([":", ";", "{", "=>", "++", "--"]);
|
1070
|
+
|
1071
|
+
/*
|
1072
|
+
* Statements that can contain an `ExpressionStatement` after a closing parenthesis.
|
1073
|
+
* DoWhileStatement is an exception in that it always triggers ASI after the closing parenthesis.
|
1074
|
+
*/
|
1075
|
+
const STATEMENTS = new Set([
|
1076
|
+
"DoWhileStatement",
|
1077
|
+
"ForInStatement",
|
1078
|
+
"ForOfStatement",
|
1079
|
+
"ForStatement",
|
1080
|
+
"IfStatement",
|
1081
|
+
"WhileStatement",
|
1082
|
+
"WithStatement"
|
1083
|
+
]);
|
1084
|
+
|
1085
|
+
needsPrecedingSemicolon =
|
1086
|
+
function(sourceCode, node) {
|
1087
|
+
const prevToken = sourceCode.getTokenBefore(node);
|
1088
|
+
|
1089
|
+
if (!prevToken || prevToken.type === "Punctuator" && PUNCTUATORS.has(prevToken.value)) {
|
1090
|
+
return false;
|
1091
|
+
}
|
1092
|
+
|
1093
|
+
const prevNode = sourceCode.getNodeByRangeIndex(prevToken.range[0]);
|
1094
|
+
|
1095
|
+
if (isClosingParenToken(prevToken)) {
|
1096
|
+
return !STATEMENTS.has(prevNode.type);
|
1097
|
+
}
|
1098
|
+
|
1099
|
+
if (isClosingBraceToken(prevToken)) {
|
1100
|
+
return (
|
1101
|
+
prevNode.type === "BlockStatement" && prevNode.parent.type === "FunctionExpression" ||
|
1102
|
+
prevNode.type === "ClassBody" && prevNode.parent.type === "ClassExpression" ||
|
1103
|
+
prevNode.type === "ObjectExpression"
|
1104
|
+
);
|
1105
|
+
}
|
1106
|
+
|
1107
|
+
if (IDENTIFIER_OR_KEYWORD.has(prevToken.type)) {
|
1108
|
+
if (BREAK_OR_CONTINUE.has(prevNode.parent.type)) {
|
1109
|
+
return false;
|
1110
|
+
}
|
1111
|
+
|
1112
|
+
const keyword = prevToken.value;
|
1113
|
+
const nodeType = NODE_TYPES_BY_KEYWORD[keyword];
|
1114
|
+
|
1115
|
+
return prevNode.type !== nodeType;
|
1116
|
+
}
|
1117
|
+
|
1118
|
+
if (prevToken.type === "String") {
|
1119
|
+
return !DECLARATIONS.has(prevNode.parent.type);
|
1120
|
+
}
|
1121
|
+
|
1122
|
+
return true;
|
1123
|
+
};
|
1124
|
+
}
|
1125
|
+
|
1018
1126
|
//------------------------------------------------------------------------------
|
1019
1127
|
// Public Interface
|
1020
1128
|
//------------------------------------------------------------------------------
|
@@ -2168,5 +2276,7 @@ module.exports = {
|
|
2168
2276
|
getModuleExportName,
|
2169
2277
|
isConstant,
|
2170
2278
|
isTopLevelExpressionStatement,
|
2171
|
-
isDirective
|
2279
|
+
isDirective,
|
2280
|
+
isStartOfExpressionStatement,
|
2281
|
+
needsPrecedingSemicolon
|
2172
2282
|
};
|
package/lib/rules/wrap-iife.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to flag when IIFE is not wrapped in parens
|
3
3
|
* @author Ilya Volodin
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -40,6 +41,8 @@ function isCalleeOfNewExpression(node) {
|
|
40
41
|
/** @type {import('../shared/types').Rule} */
|
41
42
|
module.exports = {
|
42
43
|
meta: {
|
44
|
+
deprecated: true,
|
45
|
+
replacedBy: [],
|
43
46
|
type: "layout",
|
44
47
|
|
45
48
|
docs: {
|
package/lib/rules/wrap-regex.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to flag when regex literals are not wrapped in parens
|
3
3
|
* @author Matt DuVall <http://www.mattduvall.com>
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -12,6 +13,8 @@
|
|
12
13
|
/** @type {import('../shared/types').Rule} */
|
13
14
|
module.exports = {
|
14
15
|
meta: {
|
16
|
+
deprecated: true,
|
17
|
+
replacedBy: [],
|
15
18
|
type: "layout",
|
16
19
|
|
17
20
|
docs: {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to check the spacing around the * in yield* expressions.
|
3
3
|
* @author Bryan Smith
|
4
|
+
* @deprecated in ESLint v8.53.0
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -12,6 +13,8 @@
|
|
12
13
|
/** @type {import('../shared/types').Rule} */
|
13
14
|
module.exports = {
|
14
15
|
meta: {
|
16
|
+
deprecated: true,
|
17
|
+
replacedBy: [],
|
15
18
|
type: "layout",
|
16
19
|
|
17
20
|
docs: {
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Helpers for severity values (e.g. normalizing different types).
|
3
|
+
* @author Bryan Mishkin
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Convert severity value of different types to a string.
|
10
|
+
* @param {string|number} severity severity value
|
11
|
+
* @throws error if severity is invalid
|
12
|
+
* @returns {string} severity string
|
13
|
+
*/
|
14
|
+
function normalizeSeverityToString(severity) {
|
15
|
+
if ([2, "2", "error"].includes(severity)) {
|
16
|
+
return "error";
|
17
|
+
}
|
18
|
+
if ([1, "1", "warn"].includes(severity)) {
|
19
|
+
return "warn";
|
20
|
+
}
|
21
|
+
if ([0, "0", "off"].includes(severity)) {
|
22
|
+
return "off";
|
23
|
+
}
|
24
|
+
throw new Error(`Invalid severity value: ${severity}`);
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Convert severity value of different types to a number.
|
29
|
+
* @param {string|number} severity severity value
|
30
|
+
* @throws error if severity is invalid
|
31
|
+
* @returns {number} severity number
|
32
|
+
*/
|
33
|
+
function normalizeSeverityToNumber(severity) {
|
34
|
+
if ([2, "2", "error"].includes(severity)) {
|
35
|
+
return 2;
|
36
|
+
}
|
37
|
+
if ([1, "1", "warn"].includes(severity)) {
|
38
|
+
return 1;
|
39
|
+
}
|
40
|
+
if ([0, "0", "off"].includes(severity)) {
|
41
|
+
return 0;
|
42
|
+
}
|
43
|
+
throw new Error(`Invalid severity value: ${severity}`);
|
44
|
+
}
|
45
|
+
|
46
|
+
module.exports = {
|
47
|
+
normalizeSeverityToString,
|
48
|
+
normalizeSeverityToNumber
|
49
|
+
};
|