voss-node-configs 1.0.71 → 1.0.72
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/base.js +10 -11
- package/front-end.js +37 -2
- package/package.json +1 -1
package/base.js
CHANGED
|
@@ -4,6 +4,15 @@ import typescriptParser from '@typescript-eslint/parser';
|
|
|
4
4
|
import eslintConfigPrettier from 'eslint-config-prettier';
|
|
5
5
|
import prettierPlugin from 'eslint-plugin-prettier';
|
|
6
6
|
|
|
7
|
+
// Named const required when a conditional would otherwise be the property
|
|
8
|
+
// value. Spreads that optionally include a property stay allowed:
|
|
9
|
+
// ...(ready ? { status: 'ready' } : {})
|
|
10
|
+
export const noConditionalPropertyValue = {
|
|
11
|
+
selector: 'Property[value.type="ConditionalExpression"]',
|
|
12
|
+
message:
|
|
13
|
+
'Extract the conditional into a named const instead of using it as an object property value.',
|
|
14
|
+
};
|
|
15
|
+
|
|
7
16
|
export default [
|
|
8
17
|
js.configs.recommended,
|
|
9
18
|
{
|
|
@@ -65,17 +74,7 @@ export default [
|
|
|
65
74
|
'object-shorthand': ['error', 'properties'],
|
|
66
75
|
'prefer-destructuring': 'off',
|
|
67
76
|
|
|
68
|
-
|
|
69
|
-
// value. Spreads that optionally include a property stay allowed:
|
|
70
|
-
// ...(ready ? { status: 'ready' } : {})
|
|
71
|
-
'no-restricted-syntax': [
|
|
72
|
-
'error',
|
|
73
|
-
{
|
|
74
|
-
selector: 'Property[value.type="ConditionalExpression"]',
|
|
75
|
-
message:
|
|
76
|
-
'Extract the conditional into a named const instead of using it as an object property value.',
|
|
77
|
-
},
|
|
78
|
-
],
|
|
77
|
+
'no-restricted-syntax': ['error', noConditionalPropertyValue],
|
|
79
78
|
},
|
|
80
79
|
},
|
|
81
80
|
// Turn off ESLint rules that conflict with Prettier (must come after other configs)
|
package/front-end.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import baseConfig from './base.js';
|
|
1
|
+
import baseConfig, { noConditionalPropertyValue } from './base.js';
|
|
2
2
|
import reactHooks from 'eslint-plugin-react-hooks';
|
|
3
3
|
import globals from 'globals';
|
|
4
4
|
|
|
5
|
+
const IN_PAGE_CALLBACK =
|
|
6
|
+
'CallExpression[callee.property.name=/^(evaluate|evaluateAll|evaluateHandle|\\$eval|\\$\\$eval|waitForFunction|addInitScript)$/] > :matches(ArrowFunctionExpression, FunctionExpression)';
|
|
7
|
+
const CLICK_EVENT_TYPE = '/^(click|dblclick|mousedown|mouseup|pointerdown|pointerup)$/';
|
|
8
|
+
const REAL_CLICK_MESSAGE =
|
|
9
|
+
'A script click reaches elements a user cannot, so the test passes when the page is broken. Use a real click: locator.click().';
|
|
10
|
+
|
|
5
11
|
export default [
|
|
6
12
|
...baseConfig,
|
|
7
13
|
reactHooks.configs['recommended-latest'],
|
|
@@ -38,4 +44,33 @@ export default [
|
|
|
38
44
|
globals: { ...globals.node },
|
|
39
45
|
},
|
|
40
46
|
},
|
|
41
|
-
|
|
47
|
+
// Playwright tests must click like a user. Flat config replaces a rule's value
|
|
48
|
+
// rather than merging it, so this restates the base entry.
|
|
49
|
+
{
|
|
50
|
+
files: ['e2e/**/*.ts'],
|
|
51
|
+
rules: {
|
|
52
|
+
'no-restricted-syntax': [
|
|
53
|
+
'error',
|
|
54
|
+
noConditionalPropertyValue,
|
|
55
|
+
{
|
|
56
|
+
selector: `${IN_PAGE_CALLBACK} CallExpression[callee.property.name="click"]`,
|
|
57
|
+
message: REAL_CLICK_MESSAGE,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
selector: `CallExpression[callee.property.name="dispatchEvent"][arguments.0.value=${CLICK_EVENT_TYPE}]`,
|
|
61
|
+
message: REAL_CLICK_MESSAGE,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
selector: `NewExpression[callee.name=/^(Event|MouseEvent|PointerEvent)$/][arguments.0.value=${CLICK_EVENT_TYPE}]`,
|
|
65
|
+
message: REAL_CLICK_MESSAGE,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
selector:
|
|
69
|
+
'CallExpression[callee.property.name=/^(click|dblclick|tap|check|uncheck|setChecked|hover)$/] > ObjectExpression > Property[key.name="force"][value.value=true]',
|
|
70
|
+
message:
|
|
71
|
+
'force: true skips the check that a user could reach the element. Fix what covers it, or use page.mouse for a click at a position.',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
];
|