@samitouri / QOS-React / commits / afbc2d08f4

Remove unused react-internal/invariant-args ESLint rule. (#22778)

Esteban committed Nov 16, 2021 at 21:11 UTC afbc2d08f4dabf00222e9561344b65e51d6ed190
8 files changed -202
.eslintrc.js
-1
@@ -113,7 +113,6 @@ module.exports = {
113 {isProductionUserAppCode: true},
114 ],
115 'react-internal/no-to-warn-dev-within-to-throw': ERROR,
116 - 'react-internal/invariant-args': ERROR,
116 'react-internal/warning-args': ERROR,
117 'react-internal/no-production-logging': ERROR,
118 'react-internal/no-cross-fork-imports': ERROR,
packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager.js
-2
@@ -5,8 +5,6 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -/* eslint-disable react-internal/invariant-args */
9 -
8 'use strict';
9
10 // Mock of the Native Hooks
packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativeViewConfigRegistry.js
-2
@@ -7,8 +7,6 @@
7 * @flow strict-local
8 */
9
10 -/* eslint-disable react-internal/invariant-args */
11 -
10 'use strict';
11
12 import type {
packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/UIManager.js
-2
@@ -5,8 +5,6 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -/* eslint-disable react-internal/invariant-args */
9 -
8 'use strict';
9
10 // Mock of the Native Hooks
scripts/eslint-rules/__tests__/invariant-args-test.internal.js deleted
-83
@@ -1,83 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @emails react-core
8 - */
9 -
10 -'use strict';
11 -
12 -const rule = require('../invariant-args');
13 -const {RuleTester} = require('eslint');
14 -const ruleTester = new RuleTester();
15 -
16 -ruleTester.run('eslint-rules/invariant-args', rule, {
17 - valid: [
18 - 'arbitraryFunction(a, b)',
19 - // These messages are in the error code map
20 - "invariant(false, 'Do not override existing functions.')",
21 - "invariant(false, 'createRoot(...): Target container is not a DOM element.')",
22 - ],
23 - invalid: [
24 - {
25 - code: "invariant('hello, world');",
26 - errors: [
27 - {
28 - message: 'invariant takes at least two arguments',
29 - },
30 - ],
31 - },
32 - {
33 - code: 'invariant(true, null);',
34 - errors: [
35 - {
36 - message: 'The second argument to invariant must be a string literal',
37 - },
38 - ],
39 - },
40 - {
41 - code: 'var g = 5; invariant(true, g);',
42 - errors: [
43 - {
44 - message: 'The second argument to invariant must be a string literal',
45 - },
46 - ],
47 - },
48 - {
49 - code: "invariant(true, 'error!');",
50 - errors: [
51 - {
52 - message:
53 - 'The invariant format should be able to uniquely identify this ' +
54 - 'invariant. Please, use a more descriptive format than: error!',
55 - },
56 - ],
57 - },
58 - {
59 - code: "invariant(true, '%s %s, %s %s: %s (%s)', 1, 2, 3, 4, 5, 6);",
60 - errors: [
61 - {
62 - message:
63 - 'The invariant format should be able to uniquely identify this ' +
64 - 'invariant. Please, use a more descriptive format than: ' +
65 - '%s %s, %s %s: %s (%s)',
66 - },
67 - ],
68 - },
69 - {
70 - code: "invariant(false, 'Not in error map')",
71 - errors: [
72 - {
73 - message:
74 - 'Error message does not have a corresponding production error code.\n\n' +
75 - 'Run `yarn extract-errors` to add the message to error code map, ' +
76 - 'so it can be stripped from the production builds. ' +
77 - "Alternatively, if you're updating an existing error message, " +
78 - 'you can modify `scripts/error-codes/codes.json` directly.',
79 - },
80 - ],
81 - },
82 - ],
83 -});
scripts/eslint-rules/index.js
-1
@@ -5,7 +5,6 @@ module.exports = {
5 'no-primitive-constructors': require('./no-primitive-constructors'),
6 'no-to-warn-dev-within-to-throw': require('./no-to-warn-dev-within-to-throw'),
7 'warning-args': require('./warning-args'),
8 - 'invariant-args': require('./invariant-args'),
8 'prod-error-codes': require('./prod-error-codes'),
9 'no-production-logging': require('./no-production-logging'),
10 'no-cross-fork-imports': require('./no-cross-fork-imports'),
scripts/eslint-rules/invariant-args.js deleted
-109
@@ -1,109 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @emails react-core
8 - */
9 -
10 -'use strict';
11 -
12 -const fs = require('fs');
13 -const path = require('path');
14 -const existingErrorMap = JSON.parse(
15 - fs.readFileSync(path.resolve(__dirname, '../error-codes/codes.json'))
16 -);
17 -const messages = new Set();
18 -Object.keys(existingErrorMap).forEach(key =>
19 - messages.add(existingErrorMap[key])
20 -);
21 -
22 -/**
23 - * The warning() and invariant() functions take format strings as their second
24 - * argument.
25 - */
26 -
27 -module.exports = {
28 - meta: {
29 - schema: [],
30 - },
31 - create(context) {
32 - // we also allow literal strings and concatenated literal strings
33 - function getLiteralString(node) {
34 - if (node.type === 'Literal' && typeof node.value === 'string') {
35 - return node.value;
36 - } else if (node.type === 'BinaryExpression' && node.operator === '+') {
37 - const l = getLiteralString(node.left);
38 - const r = getLiteralString(node.right);
39 - if (l !== null && r !== null) {
40 - return l + r;
41 - }
42 - }
43 - return null;
44 - }
45 -
46 - return {
47 - CallExpression: function(node) {
48 - // This could be a little smarter by checking context.getScope() to see
49 - // how warning/invariant was defined.
50 - const isInvariant =
51 - node.callee.type === 'Identifier' && node.callee.name === 'invariant';
52 - if (!isInvariant) {
53 - return;
54 - }
55 - if (node.arguments.length < 2) {
56 - context.report(node, '{{name}} takes at least two arguments', {
57 - name: node.callee.name,
58 - });
59 - return;
60 - }
61 - const format = getLiteralString(node.arguments[1]);
62 - if (format === null) {
63 - context.report(
64 - node,
65 - 'The second argument to {{name}} must be a string literal',
66 - {name: node.callee.name}
67 - );
68 - return;
69 - }
70 - if (format.length < 10 || /^[s\W]*$/.test(format)) {
71 - context.report(
72 - node,
73 - 'The {{name}} format should be able to uniquely identify this ' +
74 - '{{name}}. Please, use a more descriptive format than: {{format}}',
75 - {name: node.callee.name, format: format}
76 - );
77 - return;
78 - }
79 - // count the number of formatting substitutions, plus the first two args
80 - const expectedNArgs = (format.match(/%s/g) || []).length + 2;
81 - if (node.arguments.length !== expectedNArgs) {
82 - context.report(
83 - node,
84 - 'Expected {{expectedNArgs}} arguments in call to {{name}} based on ' +
85 - 'the number of "%s" substitutions, but got {{length}}',
86 - {
87 - expectedNArgs: expectedNArgs,
88 - name: node.callee.name,
89 - length: node.arguments.length,
90 - }
91 - );
92 - }
93 -
94 - if (!messages.has(format)) {
95 - context.report(
96 - node,
97 - 'Error message does not have a corresponding production ' +
98 - 'error code.\n\n' +
99 - 'Run `yarn extract-errors` to add the message to error code ' +
100 - 'map, so it can be stripped from the production builds. ' +
101 - "Alternatively, if you're updating an existing error " +
102 - 'message, you can modify ' +
103 - '`scripts/error-codes/codes.json` directly.'
104 - );
105 - }
106 - },
107 - };
108 - },
109 -};
scripts/rollup/shims/react-native/ReactNativeViewConfigRegistry.js
-2
@@ -8,8 +8,6 @@
8 * @flow strict-local
9 */
10
11 -/* eslint-disable react-internal/invariant-args */
12 -
11 'use strict';
12
13 import {type ViewConfig} from './ReactNativeTypes';