diff --git a/.vscode/extensions.json b/.vscode/extensions.json index f6f5027fb..af3784e8f 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,7 @@ { "recommendations": [ "dprint.dprint", - "dbaeumer.vscode-eslint" + "dbaeumer.vscode-eslint", + "bierner.comment-tagged-templates" ] } diff --git a/eslint.config.mts b/eslint.config.mts index c414b5306..1e28c22d8 100644 --- a/eslint.config.mts +++ b/eslint.config.mts @@ -197,7 +197,23 @@ const config: FlatConfig[] = [ }, ], // Part: unicorn rules - "unicorn/template-indent": "warn", + "unicorn/template-indent": [ + "warn", + { + comments: [ + "outdent", + "dedent", + "html", + "tsx", + ], + tags: [ + "outdent", + "dedent", + "html", + "tsx", + ], + }, + ], // Part: eslint-comments rules "eslint-comments/disable-enable-pair": ["error", { allowWholeFile: true }], "eslint-comments/no-aggregating-enable": "error", diff --git a/packages/plugins/eslint-plugin-react-debug/src/rules/class-component.spec.ts b/packages/plugins/eslint-plugin-react-debug/src/rules/class-component.spec.ts index f6e8fb386..6447fbf4e 100644 --- a/packages/plugins/eslint-plugin-react-debug/src/rules/class-component.spec.ts +++ b/packages/plugins/eslint-plugin-react-debug/src/rules/class-component.spec.ts @@ -1,12 +1,10 @@ -import dedent from "dedent"; - import { allValid, ruleTester } from "../../../../../test"; import rule, { RULE_NAME } from "./class-component"; ruleTester.run(RULE_NAME, rule, { invalid: [ { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { return
; @@ -16,7 +14,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "CLASS_COMPONENT" }], }, { - code: dedent` + code: /* tsx */ ` const ClassComponent = class extends React.Component { render() { return
; @@ -26,7 +24,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "CLASS_COMPONENT" }], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { class UnstableNestedClassComponent extends React.Component { render() { @@ -44,7 +42,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "CLASS_COMPONENT" }], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { class UnstableNestedClassComponent extends React.Component { @@ -67,7 +65,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { class UnstableNestedClassComponent extends React.Component { @@ -90,7 +88,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { function UnstableNestedFunctionComponent() { @@ -108,7 +106,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "CLASS_COMPONENT" }], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { function UnstableNestedClassComponent() { @@ -126,7 +124,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "CLASS_COMPONENT" }], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { const UnstableNestedVariableComponent = () => { @@ -144,25 +142,25 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "CLASS_COMPONENT" }], }, { - code: ` - class ParentComponent extends React.Component { - render() { - const UnstableNestedClassComponent = () => { - return React.createElement("div", null); - } - - return React.createElement( - "div", - null, - React.createElement(UnstableNestedClassComponent, null) - ); - } + code: /* tsx */ ` + class ParentComponent extends React.Component { + render() { + const UnstableNestedClassComponent = () => { + return React.createElement("div", null); } - `, + + return React.createElement( + "div", + null, + React.createElement(UnstableNestedClassComponent, null) + ); + } + } + `, errors: [{ messageId: "CLASS_COMPONENT" }], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { const List = () => { @@ -176,7 +174,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "CLASS_COMPONENT" }], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { const List = (props) => { diff --git a/packages/plugins/eslint-plugin-react-debug/src/rules/function-component.spec.ts b/packages/plugins/eslint-plugin-react-debug/src/rules/function-component.spec.ts index 910857ca7..4be86d028 100644 --- a/packages/plugins/eslint-plugin-react-debug/src/rules/function-component.spec.ts +++ b/packages/plugins/eslint-plugin-react-debug/src/rules/function-component.spec.ts @@ -1,12 +1,10 @@ -import dedent from "dedent"; - import { allFunctions, ruleTester } from "../../../../../test"; import rule, { RULE_NAME } from "./function-component"; ruleTester.run(RULE_NAME, rule, { invalid: [ { - code: dedent` + code: /* tsx */ ` function App() { return
foo
} @@ -24,7 +22,9 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: "const App = () =>
foo
", + code: /* tsx */ ` + const App = () =>
foo
+ `, errors: [{ data: { name: "App", @@ -36,7 +36,9 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: "const App = React.memo(() =>
foo
)", + code: /* tsx */ ` + const App = React.memo(() =>
foo
) + `, errors: [{ data: { name: "App", @@ -48,7 +50,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` const App = React.memo(function App() { return
foo
}) @@ -66,7 +68,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` const App = React.memo(function App() { const [state, setState] = useState(0); @@ -86,7 +88,9 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: "const App = React.forwardRef(() =>
foo
)", + code: /* tsx */ ` + const App = React.forwardRef(() =>
foo
) + `, errors: [{ data: { name: "App", @@ -98,7 +102,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` import { memo } from "react"; const MemoComponent = memo(() =>
) @@ -114,7 +118,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` import { memo } from "react"; const MemoComponent = memo(function Component() { @@ -133,7 +137,9 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: "const ForwardRefComponent = React.forwardRef(() =>
)", + code: /* tsx */ ` + const ForwardRefComponent = React.forwardRef(() =>
) + `, errors: [{ data: { name: "ForwardRefComponent", @@ -145,7 +151,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` import { memo, forwardRef } from "react"; const MemoForwardRefComponent = memo(forwardRef(() =>
)) @@ -161,7 +167,9 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: "const MemoForwardRefComponent = React.memo(React.forwardRef(() =>
))", + code: /* tsx */ ` + const MemoForwardRefComponent = React.memo(React.forwardRef(() =>
)) + `, errors: [{ data: { name: "MemoForwardRefComponent", @@ -173,7 +181,9 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: "const App = () => React.createElement('div', null, 'foo')", + code: /* tsx */ ` + const App = () => React.createElement('div', null, 'foo') + `, errors: [{ data: { name: "App", @@ -185,7 +195,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { function UnstableNestedFunctionComponent() { return
; @@ -220,7 +230,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { function UnstableNestedFunctionComponent() { return React.createElement("div", null); @@ -255,7 +265,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { const UnstableNestedVariableComponent = () => { return
; @@ -290,7 +300,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { const UnstableNestedVariableComponent = () => { return React.createElement("div", null); @@ -325,7 +335,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` const ParentComponent = () => { function UnstableNestedFunctionComponent() { return
; @@ -360,7 +370,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` const ParentComponent = () => { function UnstableNestedFunctionComponent() { return React.createElement("div", null); @@ -395,7 +405,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` export default () => { function UnstableNestedFunctionComponent() { return
; @@ -430,7 +440,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` export default () => { function UnstableNestedFunctionComponent() { return React.createElement("div", null); @@ -465,7 +475,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` const ParentComponent = () => { const UnstableNestedVariableComponent = () => { return
; @@ -500,7 +510,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` const ParentComponent = () => { const UnstableNestedVariableComponent = () => { return React.createElement("div", null); @@ -535,7 +545,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { class UnstableNestedClassComponent extends React.Component { render() { @@ -561,7 +571,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { class UnstableNestedClassComponent extends React.Component { render() { @@ -587,7 +597,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { function UnstableNestedFunctionComponent() { @@ -613,7 +623,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { function UnstableNestedClassComponent() { @@ -639,7 +649,7 @@ ruleTester.run(RULE_NAME, rule, { }], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { const UnstableNestedVariableComponent = () => { @@ -693,7 +703,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { function getComponent() { function NestedUnstableFunctionComponent() { @@ -732,7 +742,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { function getComponent() { function NestedUnstableFunctionComponent() { @@ -767,7 +777,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ComponentWithProps(props) { return
; } @@ -805,7 +815,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ComponentWithProps(props) { return React.createElement("div", null); } @@ -849,7 +859,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ComponentWithProps(props) { return
; } @@ -882,7 +892,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ComponentWithProps(props) { return React.createElement("div", null); } @@ -915,7 +925,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function RenderPropComponent(props) { return props.render({}); } @@ -960,7 +970,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ComponentForProps(props) { return
; } @@ -993,7 +1003,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ComponentForProps(props) { return React.createElement("div", null); } @@ -1026,7 +1036,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { return (
}} /> @@ -1055,7 +1065,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { const List = () => { @@ -1079,7 +1089,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` class ParentComponent extends React.Component { render() { const List = (props) => { @@ -1110,7 +1120,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { return ( @@ -1138,7 +1148,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { const thingElement = thing.match({ loading: () =>
, @@ -1165,7 +1175,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { const rows = [ { @@ -1190,7 +1200,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { const UnstableNestedComponent = React.memo(() => { return
; @@ -1225,7 +1235,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { const UnstableNestedComponent = React.memo( () => React.createElement("div", null), @@ -1260,7 +1270,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { const UnstableNestedComponent = React.memo( function () { @@ -1297,7 +1307,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function ParentComponent() { const UnstableNestedComponent = React.memo( function () { @@ -1336,9 +1346,9 @@ ruleTester.run(RULE_NAME, rule, { ], valid: [ ...allFunctions, - dedent`const results = data.flatMap((x) => x?.name || []) || []`, - dedent`const results = allSettled.map((x) => (x.status === 'fulfilled' ?
: null))`, - dedent`const results = allSettled.map((x) => (x.status === 'fulfilled' ? format(x.value) : null))`, - dedent`const results = allSettled.mapLike((x) => (x.status === 'fulfilled' ? format(x.value) : null))`, + "const results = data.flatMap((x) => x?.name || []) || []", + "const results = allSettled.map((x) => (x.status === 'fulfilled' ?
: null))", + "const results = allSettled.map((x) => (x.status === 'fulfilled' ? format(x.value) : null))", + "const results = allSettled.mapLike((x) => (x.status === 'fulfilled' ? format(x.value) : null))", ], }); diff --git a/packages/plugins/eslint-plugin-react-debug/src/rules/react-hooks.spec.ts b/packages/plugins/eslint-plugin-react-debug/src/rules/react-hooks.spec.ts index 6f0609b10..0eecb5550 100644 --- a/packages/plugins/eslint-plugin-react-debug/src/rules/react-hooks.spec.ts +++ b/packages/plugins/eslint-plugin-react-debug/src/rules/react-hooks.spec.ts @@ -1,12 +1,10 @@ -import dedent from "dedent"; - import { allFunctions, ruleTester } from "../../../../../test"; import rule, { RULE_NAME } from "./react-hooks"; ruleTester.run(RULE_NAME, rule, { invalid: [ { - code: dedent` + code: /* tsx */ ` function useToggle() { const [value, setValue] = useState(false); return [value, () => setValue(x => !x)]; @@ -23,7 +21,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` // 🔴 Avoid: A Hook that doesn't use Hooks function useSorted(items) { return items.slice().sort(); @@ -40,7 +38,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function useToggle() { const [value, setValue] = useState(false); return [value, () => setValue(x => !x)]; @@ -69,7 +67,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` const useClassnames = (obj) => { // Invalid, because useClassnames doesn't use any other React Hooks. var k, cls=''; @@ -93,7 +91,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` function useClassnames(obj) { // Invalid, because useClassnames doesn't use any other React Hooks. var k, cls=''; @@ -117,7 +115,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` export function useNestedHook() { const [state, setState] = useState("state"); const useInnerHook = () => { @@ -145,7 +143,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` export function useNestedHook() { const useInnerHook = () => { const [state, setState] = useState("state"); @@ -173,7 +171,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` export function useNestedHook() { const fn = () => { const [state, setState] = useState("state"); diff --git a/packages/plugins/eslint-plugin-react-dom/src/rules/no-children-in-void-dom-elements.spec.ts b/packages/plugins/eslint-plugin-react-dom/src/rules/no-children-in-void-dom-elements.spec.ts index 2d16d46c2..aece62865 100644 --- a/packages/plugins/eslint-plugin-react-dom/src/rules/no-children-in-void-dom-elements.spec.ts +++ b/packages/plugins/eslint-plugin-react-dom/src/rules/no-children-in-void-dom-elements.spec.ts @@ -1,12 +1,10 @@ -import dedent from "dedent"; - import { allValid, ruleTester } from "../../../../../test"; import rule, { RULE_NAME } from "./no-children-in-void-dom-elements"; ruleTester.run(RULE_NAME, rule, { invalid: [ { - code: "
Foo
;", + code: /* tsx */ `
Foo
;`, errors: [ { data: { element: "br" }, @@ -15,7 +13,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: '
;', + code: /* tsx */ `
;`, errors: [ { data: { element: "br" }, @@ -24,7 +22,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: ';', + code: /* tsx */ `;`, errors: [ { data: { element: "img" }, @@ -33,7 +31,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: '
;', + code: /* tsx */ `
;`, errors: [ { data: { element: "br" }, @@ -42,7 +40,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: 'React.createElement("br", {}, "Foo");', + code: /* tsx */ `React.createElement("br", {}, "Foo");`, errors: [ { data: { element: "br" }, @@ -51,7 +49,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: 'React.createElement("br", { children: "Foo" });', + code: /* tsx */ `React.createElement("br", { children: "Foo" });`, errors: [ { data: { element: "br" }, @@ -60,7 +58,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: 'React.createElement("br", { dangerouslySetInnerHTML: { __html: "Foo" } });', + code: /* tsx */ `React.createElement("br", { dangerouslySetInnerHTML: { __html: "Foo" } });`, errors: [ { data: { element: "br" }, @@ -69,7 +67,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` import React, {createElement} from "react"; createElement("img", {}, "Foo"); `, @@ -81,7 +79,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` import React, {createElement} from "react"; createElement("img", { children: "Foo" }); `, @@ -93,7 +91,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` import React, {createElement} from "react"; createElement("img", { dangerouslySetInnerHTML: { __html: "Foo" } }); `, @@ -109,39 +107,27 @@ ruleTester.run(RULE_NAME, rule, { ...allValid, "
Foo
;", '
;', - '
;', - 'React.createElement("div", {}, "Foo");', - 'React.createElement("div", { children: "Foo" });', - 'React.createElement("div", { dangerouslySetInnerHTML: { __html: "Foo" } });', - 'document.createElement("img");', - 'React.createElement("img");', - "React.createElement();", - "document.createElement();", - - dedent` + /* tsx */ ` const props = {}; React.createElement("img", props); `, - - dedent` + /* tsx */ ` import React, {createElement} from "react"; createElement("div"); `, - - dedent` + /* tsx */ ` import React, {createElement} from "react"; createElement("img"); `, - - dedent` + /* tsx */ ` import React, {createElement, PureComponent} from "react"; class Button extends PureComponent { handleClick(ev) { diff --git a/packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml-with-children.spec.ts b/packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml-with-children.spec.ts index dfb22c51d..713fbed89 100644 --- a/packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml-with-children.spec.ts +++ b/packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml-with-children.spec.ts @@ -1,72 +1,81 @@ -import dedent from "dedent"; - import { allValid, ruleTester } from "../../../../../test"; import rule, { RULE_NAME } from "./no-dangerously-set-innerhtml-with-children"; ruleTester.run(RULE_NAME, rule, { invalid: [ { - code: '
Children
', + code: /* tsx */ `
Children
`, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: '
', + code: /* tsx */ `
`, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: `const props = { dangerouslySetInnerHTML: { __html: "HTML" } } - ;
Children
`, + code: /* tsx */ ` + const props = { dangerouslySetInnerHTML: { __html: "HTML" } } + ;
Children
+ `, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: `const props = { children: "Children", dangerouslySetInnerHTML: { __html: "HTML" } } - ;
`, + code: /* tsx */ ` + const props = { children: "Children", dangerouslySetInnerHTML: { __html: "HTML" } } + ;
+ `, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: 'Children', + code: /* tsx */ `Children`, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: '', + code: /* tsx */ ``, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: ' ', + code: /* tsx */ ` `, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: 'React.createElement("div", { dangerouslySetInnerHTML: { __html: "HTML" } }, "Children")', + code: /* tsx */ `React.createElement("div", { dangerouslySetInnerHTML: { __html: "HTML" } }, "Children")`, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: 'React.createElement("div", { dangerouslySetInnerHTML: { __html: "HTML" }, children: "Children" })', + code: + /* tsx */ `React.createElement("div", { dangerouslySetInnerHTML: { __html: "HTML" }, children: "Children" })`, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: 'React.createElement("App", { dangerouslySetInnerHTML: { __html: "HTML" } }, "Children")', + code: /* tsx */ `React.createElement("App", { dangerouslySetInnerHTML: { __html: "HTML" } }, "Children")`, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: 'React.createElement("App", { dangerouslySetInnerHTML: { __html: "HTML" }, children: "Children" })', + code: + /* tsx */ `React.createElement("App", { dangerouslySetInnerHTML: { __html: "HTML" }, children: "Children" })`, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: `const props = { dangerouslySetInnerHTML: { __html: "HTML" } } - React.createElement("div", props, "Children")`, + code: /* tsx */ ` + const props = { dangerouslySetInnerHTML: { __html: "HTML" } } + React.createElement("div", props, "Children") + `, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: `const props = { children: "Children", dangerouslySetInnerHTML: { __html: "HTML" } } - React.createElement("div", props)`, + code: /* tsx */ ` + const props = { children: "Children", dangerouslySetInnerHTML: { __html: "HTML" } } + React.createElement("div", props) + `, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, { - code: ` - const moreProps = { children: "Children" } - const otherProps = { ...moreProps } - const props = { ...otherProps, dangerouslySetInnerHTML: { __html: "HTML" } } - React.createElement("div", props)`, + code: /* tsx */ ` + const moreProps = { children: "Children" } + const otherProps = { ...moreProps } + const props = { ...otherProps, dangerouslySetInnerHTML: { __html: "HTML" } } + React.createElement("div", props) + `, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML_WITH_CHILDREN" }], }, ], @@ -76,16 +85,16 @@ ruleTester.run(RULE_NAME, rule, { "
", '
', '
', - dedent` + /* tsx */ ` const props = { dangerouslySetInnerHTML: { __html: "HTML" } } const div =
`, - dedent` + /* tsx */ ` const moreProps = { className: "eslint" } const props = { children: "Children", ...moreProps } const div =
`, - dedent` + /* tsx */ ` const otherProps = { children: "Children" } const { a, b, ...props } = otherProps const div =
@@ -93,13 +102,13 @@ ruleTester.run(RULE_NAME, rule, { "Children", '', '\n', - dedent` + /* tsx */ ` React.createElement("div", { dangerouslySetInnerHTML: { __html: "HTML" } }) `, 'React.createElement("div", {}, "Children")', - dedent` + /* tsx */ ` React.createElement("App", { dangerouslySetInnerHTML: { __html: "HTML" } }) @@ -107,7 +116,9 @@ ruleTester.run(RULE_NAME, rule, { 'React.createElement("App", {}, "Children")', "Children", 'React.createElement("App", undefined, "Children")', - `const props = { ...props, scratch: {mode: 'edit'} } - const component = shallow()`, + /* tsx */ ` + const props = { ...props, scratch: {mode: 'edit'} } + const component = shallow() + `, ], }); diff --git a/packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml.spec.ts b/packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml.spec.ts index ce9cdbd6a..3ce35406c 100644 --- a/packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml.spec.ts +++ b/packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml.spec.ts @@ -1,20 +1,18 @@ -import dedent from "dedent"; - import { allValid, ruleTester } from "../../../../../test"; import rule, { RULE_NAME } from "./no-dangerously-set-innerhtml"; ruleTester.run(RULE_NAME, rule, { invalid: [ { - code: '
Children
', + code: /* tsx */ `
Children
`, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML" }], }, { - code: '
', + code: /* tsx */ `
`, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML" }], }, { - code: dedent` + code: /* tsx */ ` const props = { dangerouslySetInnerHTML: { __html: "HTML" } } @@ -23,7 +21,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML" }], }, { - code: dedent` + code: /* tsx */ ` const props = { children: "Children", dangerouslySetInnerHTML: { __html: "HTML" } @@ -61,17 +59,21 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML" }], }, { - code: `const props = { dangerouslySetInnerHTML: { __html: "HTML" } } - React.createElement("div", props, "Children")`, + code: /* tsx */ ` + const props = { dangerouslySetInnerHTML: { __html: "HTML" } } + React.createElement("div", props, "Children") + `, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML" }], }, { - code: `const props = { children: "Children", dangerouslySetInnerHTML: { __html: "HTML" } } - React.createElement("div", props)`, + code: /* tsx */ ` + const props = { children: "Children", dangerouslySetInnerHTML: { __html: "HTML" } } + React.createElement("div", props) + `, errors: [{ messageId: "NO_DANGEROUSLY_SET_INNERHTML" }], }, { - code: dedent` + code: /* tsx */ ` const moreProps = { children: "Children" } const otherProps = { ...moreProps } const props = { ...otherProps, dangerouslySetInnerHTML: { __html: "HTML" } } diff --git a/packages/plugins/eslint-plugin-react-dom/src/rules/no-find-dom-node.spec.ts b/packages/plugins/eslint-plugin-react-dom/src/rules/no-find-dom-node.spec.ts index 01815c63e..cfef7eb1e 100644 --- a/packages/plugins/eslint-plugin-react-dom/src/rules/no-find-dom-node.spec.ts +++ b/packages/plugins/eslint-plugin-react-dom/src/rules/no-find-dom-node.spec.ts @@ -1,12 +1,10 @@ -import dedent from "dedent"; - import { allValid, ruleTester } from "../../../../../test"; import rule, { RULE_NAME } from "./no-find-dom-node"; ruleTester.run(RULE_NAME, rule, { invalid: [ { - code: dedent` + code: /* tsx */ ` import ReactDOM from "react-dom"; export const Component = () => { @@ -18,7 +16,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` import { findDOMNode } from "react-dom"; export const Component = () => { @@ -31,7 +29,7 @@ ruleTester.run(RULE_NAME, rule, { }, { - code: ` + code: /* tsx */ ` var Hello = createReactClass({ componentDidMount: function() { React.findDOMNode(this).scrollIntoView(); @@ -44,7 +42,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "NO_FIND_DOM_NODE" }], }, { - code: ` + code: /* tsx */ ` var Hello = createReactClass({ componentDidMount: function() { ReactDOM.findDOMNode(this).scrollIntoView(); @@ -57,7 +55,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "NO_FIND_DOM_NODE" }], }, { - code: ` + code: /* tsx */ ` class Hello extends Component { componentDidMount() { findDOMNode(this).scrollIntoView(); @@ -70,7 +68,7 @@ ruleTester.run(RULE_NAME, rule, { errors: [{ messageId: "NO_FIND_DOM_NODE" }], }, { - code: ` + code: /* tsx */ ` class Hello extends Component { componentDidMount() { this.node = findDOMNode(this); diff --git a/packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-button-type.spec.ts b/packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-button-type.spec.ts index 06f45e0e0..67831abbe 100644 --- a/packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-button-type.spec.ts +++ b/packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-button-type.spec.ts @@ -1,12 +1,10 @@ -import dedent from "dedent"; - import { allValid, ruleTester } from "../../../../../test"; import rule, { RULE_NAME } from "./no-missing-button-type"; ruleTester.run(RULE_NAME, rule, { invalid: [ { - code: ";", + code: /* tsx */ `;`, errors: [ { messageId: "NO_MISSING_BUTTON_TYPE", @@ -14,7 +12,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` import React from "react"; function App() { @@ -28,7 +26,7 @@ ruleTester.run(RULE_NAME, rule, { ], }, { - code: dedent` + code: /* tsx */ ` import { createElement } from "react"; function App() { @@ -48,38 +46,38 @@ ruleTester.run(RULE_NAME, rule, { ";", ';', 'const Button = () => ;', - dedent` + /* tsx */ ` function App() { return ; } `, - dedent` + /* tsx */ ` function App() { return ; } `, - dedent` + /* tsx */ ` import React from "react"; function App() { return React.createElement("button", { type: "button" }, "Click me"); } `, - dedent` + /* tsx */ ` import { createElement } from "react"; function App() { return createElement("button", { type: "button" }, "Click me"); } `, - dedent` + /* tsx */ ` import { createElement } from "react"; function App() { return createElement("button", { type: true ? "button" : "submit" }, "Click me"); } `, - dedent` + /* tsx */ ` const props = { type: "button", }; diff --git a/packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-iframe-sandbox.spec.ts b/packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-iframe-sandbox.spec.ts index c5f5fc73f..051ffe850 100644 --- a/packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-iframe-sandbox.spec.ts +++ b/packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-iframe-sandbox.spec.ts @@ -1,12 +1,10 @@ -import dedent from "dedent"; - import { allValid, ruleTester } from "../../../../../test"; import rule, { RULE_NAME } from "./no-missing-iframe-sandbox"; ruleTester.run(RULE_NAME, rule, { invalid: [ { - code: "