eslint-plugin-crisp 1.7.7 → 1.7.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/package.json
CHANGED
|
@@ -94,6 +94,31 @@ function isReference(node) {
|
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
// Checks an inline object only contains references (no computed values)
|
|
98
|
+
function isReferenceObject(node) {
|
|
99
|
+
node = unwrapTransparentExpression(node);
|
|
100
|
+
|
|
101
|
+
if (!node || node.type !== "ObjectExpression") {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return node.properties.every((property) => {
|
|
106
|
+
if (property.type === "SpreadElement") {
|
|
107
|
+
return isReference(property.argument);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (property.type !== "Property" || property.kind !== "init") {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (property.computed && !isReference(property.key)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return isReference(property.value) || isReferenceObject(property.value);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
97
122
|
export default {
|
|
98
123
|
meta: {
|
|
99
124
|
type: "suggestion",
|
|
@@ -107,7 +132,7 @@ export default {
|
|
|
107
132
|
message:
|
|
108
133
|
"Logger messages must be single-line, double-quoted string literals.",
|
|
109
134
|
reference:
|
|
110
|
-
"Logger interpolation arguments must be references, not computed expressions."
|
|
135
|
+
"Logger interpolation arguments must be references or inline objects of references, not computed expressions."
|
|
111
136
|
}
|
|
112
137
|
},
|
|
113
138
|
|
|
@@ -136,7 +161,7 @@ export default {
|
|
|
136
161
|
}
|
|
137
162
|
|
|
138
163
|
for (const value of values) {
|
|
139
|
-
if (!isReference(value)) {
|
|
164
|
+
if (!isReference(value) && !isReferenceObject(value)) {
|
|
140
165
|
context.report({
|
|
141
166
|
node: value,
|
|
142
167
|
messageId: "reference"
|
|
@@ -15,6 +15,9 @@ ruleTester.run("logger-arguments", rule, {
|
|
|
15
15
|
value
|
|
16
16
|
);`,
|
|
17
17
|
"App.logger.info(\"This intentionally long logger message may exceed the usual source line length when necessary.\");",
|
|
18
|
+
"App.logger.warn(\"Shutting down\", { bufferedCount });",
|
|
19
|
+
"App.logger.warn(\"Shutting down\", { count: this.count, ...meta });",
|
|
20
|
+
"App.logger.warn(\"Shutting down\", { nested: { bufferedCount } }, logMeta);",
|
|
18
21
|
"App.logger.child({ namespace: \"worker\" });",
|
|
19
22
|
"console.info(`Unrelated logger calls are ignored: ${value}`);"
|
|
20
23
|
],
|
|
@@ -93,7 +96,15 @@ ruleTester.run("logger-arguments", rule, {
|
|
|
93
96
|
]
|
|
94
97
|
},
|
|
95
98
|
{
|
|
96
|
-
code: "App.logger.debug(\"Loaded value: %s\", { value });",
|
|
99
|
+
code: "App.logger.debug(\"Loaded value: %s\", { value: value.trim() });",
|
|
100
|
+
errors: [
|
|
101
|
+
{
|
|
102
|
+
messageId: "reference"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
code: "App.logger.debug(\"Loaded value: %s\", { value: 3 });",
|
|
97
108
|
errors: [
|
|
98
109
|
{
|
|
99
110
|
messageId: "reference"
|