mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
With #34176 we now have granular lint rules created for each compiler ErrorCategory. However, we had remnants of our old error severities still in use which makes reporting errors quite clunky. Previously you would need to specify both a category and severity which often ended up being the same. This PR moves severity definition into our rules which are generated from our categories. For now I decided to defer "upgrading" categories from a simple string to a sum type since we are only using severities to map errors to eslint severity. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34401). * #34409 * #34404 * #34403 * #34402 * __->__ #34401
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import {
|
|
ErrorCategory,
|
|
getRuleForCategory,
|
|
} from 'babel-plugin-react-compiler/src/CompilerError';
|
|
import {normalizeIndent, testRule, makeTestCaseError} from './shared-utils';
|
|
import {allRules} from '../src/rules/ReactCompilerRule';
|
|
|
|
testRule(
|
|
'no impure function calls rule',
|
|
allRules[getRuleForCategory(ErrorCategory.Purity).name].rule,
|
|
{
|
|
valid: [],
|
|
invalid: [
|
|
{
|
|
name: 'Known impure function calls are caught',
|
|
code: normalizeIndent`
|
|
function Component() {
|
|
const date = Date.now();
|
|
const now = performance.now();
|
|
const rand = Math.random();
|
|
return <Foo date={date} now={now} rand={rand} />;
|
|
}
|
|
`,
|
|
errors: [
|
|
makeTestCaseError('Cannot call impure function during render'),
|
|
makeTestCaseError('Cannot call impure function during render'),
|
|
makeTestCaseError('Cannot call impure function during render'),
|
|
],
|
|
},
|
|
],
|
|
},
|
|
);
|