mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 23:16:30 +01:00
b7661a8311
String literals provided as the third argument to assert.strictEqual() or assert.deepStrictEqual() will mask the values that are causing issues. Use a lint rule to prevent such usage. PR-URL: https://github.com/nodejs/node/pull/22849 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
61 lines
3.9 KiB
YAML
61 lines
3.9 KiB
YAML
## Test-specific linter rules
|
|
|
|
rules:
|
|
# ECMAScript 6
|
|
# http://eslint.org/docs/rules/#ecmascript-6
|
|
no-var: error
|
|
prefer-const: error
|
|
symbol-description: off
|
|
|
|
# Custom rules in tools/eslint-rules
|
|
node-core/prefer-assert-iferror: error
|
|
node-core/prefer-assert-methods: error
|
|
node-core/prefer-common-expectserror: error
|
|
node-core/prefer-common-mustnotcall: error
|
|
node-core/crypto-check: error
|
|
node-core/eslint-check: error
|
|
node-core/inspector-check: error
|
|
node-core/number-isnan: error
|
|
## common module is mandatory in tests
|
|
node-core/required-modules: [error, common]
|
|
node-core/no-duplicate-requires: off
|
|
|
|
no-restricted-syntax:
|
|
# Config copied from .eslintrc.js
|
|
- error
|
|
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='deepStrictEqual'][arguments.2.type='Literal']"
|
|
message: "Do not use a literal for the third argument of assert.deepStrictEqual()"
|
|
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='doesNotThrow']"
|
|
message: "Please replace `assert.doesNotThrow()` and add a comment next to the code instead."
|
|
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='rejects'][arguments.length<2]"
|
|
message: "assert.rejects() must be invoked with at least two arguments."
|
|
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='strictEqual'][arguments.2.type='Literal']"
|
|
message: "Do not use a literal for the third argument of assert.strictEqual()"
|
|
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])"
|
|
message: "Use an object as second argument of assert.throws()"
|
|
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.length<2]"
|
|
message: "assert.throws() must be invoked with at least two arguments."
|
|
- selector: "CallExpression[callee.name='setTimeout'][arguments.length<2]"
|
|
message: "setTimeout() must be invoked with at least two arguments."
|
|
- selector: "CallExpression[callee.name='setInterval'][arguments.length<2]"
|
|
message: "setInterval() must be invoked with at least 2 arguments."
|
|
- selector: "ThrowStatement > CallExpression[callee.name=/Error$/]"
|
|
message: "Use new keyword when throwing an Error."
|
|
# Specific to /test
|
|
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='notDeepStrictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression'])"
|
|
message: "The first argument should be the `actual`, not the `expected` value."
|
|
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='notStrictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression'])"
|
|
message: "The first argument should be the `actual`, not the `expected` value."
|
|
- selector: "CallExpression[callee.object.name='assert'][callee.property.name='deepStrictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression'])"
|
|
message: "The first argument should be the `actual`, not the `expected` value."
|
|
# TODO: Activate the `strictEqual` rule as soon as it produces less churn.
|
|
# - selector: "CallExpression[callee.object.name='assert'][callee.property.name='strictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression'])"
|
|
# message: "The first argument should be the `actual`, not the `expected` value."
|
|
# Global scoped methods and vars
|
|
globals:
|
|
WebAssembly: false
|
|
BigInt: false
|
|
BigInt64Array: false
|
|
BigUint64Array: false
|
|
SharedArrayBuffer: false
|