mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
This PR extends the previous logic added in #29141 to also account for other kinds of non-ascii characters such as `\n`. Because these control characters are individual special characters (and not 2 characters `\` and `n`) we match based on unicode which was already being checked for non-Latin characters. This allows control characters to continue to be compiled equivalently to its original source if it was provided in a JsxExpressionContainer. However note that this PR does not convert JSX attributes that are StringLiterals to JsxExpressionContainer, to preserve the original source code as it was written. Alternatively we could always emit a JsxExpressionContainer if it was used in the source and not try to down level it to some other node kind. But since we already do this I opted to keep this behavior. Partially addresses #29648. ghstack-source-id: ecc61c9f0bece90d18623b3c570fea05fbcd811a Pull Request resolved: https://github.com/facebook/react/pull/29997
107 lines
3.5 KiB
JavaScript
107 lines
3.5 KiB
JavaScript
/**
|
|
* 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.
|
|
*/
|
|
|
|
/**
|
|
* Our philosophy for linting is that lints should be very high-signal:
|
|
* - Error, don't warn. If it's worth mentioning it's worth fixing.
|
|
* - Enable rules that consistently identify real problems. If we frequently would have to
|
|
* disable the rule due to false positives, it isn't high-signal.
|
|
* - Enable rules that help improve consistent style (to avoid code review about style rather
|
|
* than substance).
|
|
*/
|
|
module.exports = {
|
|
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
rules: {
|
|
/*
|
|
* We prefer using const where variables are not reassigned, but occassional mistakes
|
|
* aren't a major issue
|
|
*/
|
|
"prefer-const": "off",
|
|
|
|
// Not valuable enough to enable
|
|
"no-useless-escape": "off",
|
|
|
|
/*
|
|
* There are valid use cases for loops with constant conditions where the body contains the
|
|
* break
|
|
*/
|
|
"no-constant-condition": "off",
|
|
|
|
// eslint only knows about builtin control flow (eg throw, return, break) and not custom ones
|
|
// like invariant.
|
|
"no-fallthrough": "off",
|
|
|
|
/*
|
|
* Low-value: this fires even for declarations that capture references which wouldn't be as
|
|
* obvious if the declaration was lifted to the parent root
|
|
*/
|
|
"no-inner-declarations": "off",
|
|
|
|
"multiline-comment-style": ["error", "starred-block"],
|
|
|
|
/**
|
|
* We sometimes need to check for control characters in regexes for things like preserving input
|
|
* strings
|
|
*/
|
|
"no-control-regex": "off",
|
|
|
|
"@typescript-eslint/no-empty-function": "off",
|
|
|
|
/*
|
|
* Explicitly casting to/through any is sometimes required, often for error messages to
|
|
* assertExhaustive()
|
|
*/
|
|
"@typescript-eslint/no-explicit-any": "off",
|
|
|
|
/*
|
|
* We use non-null assertions carefully. Ideally, there would be a TS option to codegen
|
|
* a non-null check at the assertion site.
|
|
*/
|
|
"@typescript-eslint/no-non-null-assertion": "off",
|
|
|
|
// Being explicit provides value in cases where inference may later change
|
|
"@typescript-eslint/no-inferrable-types": "off",
|
|
"@typescript-eslint/explicit-function-return-type": "error",
|
|
|
|
/*
|
|
* Unused variables are frequently a bug. Prefix unused variables with an _ to fix, but note
|
|
* that eslint won't warn you that an underscore prefixed variable is used and that the prefix
|
|
* should be dropped.
|
|
*/
|
|
"@typescript-eslint/no-unused-vars": [
|
|
"error",
|
|
{
|
|
argsIgnorePattern: "^_",
|
|
varsIgnorePattern: "^_",
|
|
caughtErrorsIgnorePattern: "^_",
|
|
},
|
|
],
|
|
|
|
// Consider enabling for consistency. Ideally violations could be auto-fixed.
|
|
"@typescript-eslint/consistent-generic-constructors": [
|
|
"off",
|
|
"constructor",
|
|
],
|
|
"@typescript-eslint/array-type": ["error", { default: "generic" }],
|
|
"@typescript-eslint/triple-slash-reference": "off",
|
|
"@typescript-eslint/no-var-requires": "off",
|
|
},
|
|
parser: "@typescript-eslint/parser",
|
|
plugins: ["@typescript-eslint"],
|
|
root: true,
|
|
ignorePatterns: ["**/__tests__/**/*", "**/*.d.ts", "**/dist/**/*"],
|
|
env: {
|
|
node: true,
|
|
},
|
|
/*
|
|
* If rules need to be disabled then the rule is insufficiently high signal
|
|
* and should be diasbled altogether or customized (in either case via a standalone PR)
|
|
*/
|
|
noInlineConfig: true,
|
|
reportUnusedDisableDirectives: true,
|
|
};
|