Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,18 @@ function runWithEnvironment(

if (env.enableValidations) {
if (env.config.validateHooksUsage) {
validateHooksUsage(hir).unwrap();
if (env.outputMode === 'lint') {
env.logErrors(validateHooksUsage(hir));
} else {
validateHooksUsage(hir).unwrap();
}
}
if (env.config.validateNoCapitalizedCalls) {
validateNoCapitalizedCalls(hir).unwrap();
if (env.outputMode === 'lint') {
env.logErrors(validateNoCapitalizedCalls(hir));
} else {
validateNoCapitalizedCalls(hir).unwrap();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ export class Environment {
return this.#scope;
}

logErrors(errors: Result<void, CompilerError>): void {
logErrors(errors: Result<unknown, CompilerError>): void {
if (errors.isOk() || this.logger == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ testRule('plugin-recommended', TestRecommendedRules, {
],
invalid: [
{
// TODO: actually return multiple diagnostics in this case
name: 'Multiple diagnostic kinds from the same function are surfaced',
code: normalizeIndent`
import Child from './Child';
Expand All @@ -70,6 +69,7 @@ testRule('plugin-recommended', TestRecommendedRules, {
`,
errors: [
makeTestCaseError('Hooks must always be called in a consistent order'),
makeTestCaseError('Capitalized functions are reserved for components'),
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* 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 {normalizeIndent, TestRecommendedRules, testRule} from './shared-utils';

testRule('repro-35394', TestRecommendedRules, {
valid: [],
invalid: [
{
name: '#35394 repro - multiple violations with useState in nested component',
code: normalizeIndent`
import {useState, useEffect} from 'react';
export default function App() {
const [foo, setFoo] = useState(false);

useEffect(() => {
setFoo(!foo);
}, []);

const ViolateStaticComponents = () => {
const [counter, setCounter] = useState(0);
return <h1>Hello, World!</h1>;
};

return (
<>
<ViolateStaticComponents />
</>
);
}
`,
errors: 3,
},
{
name: 'Without nested useState - should show 2 errors',
code: normalizeIndent`
import {useState, useEffect} from 'react';
export default function App() {
const [foo, setFoo] = useState(false);

useEffect(() => {
setFoo(!foo);
}, []);

const ViolateStaticComponents = () => {
return <h1>Hello, World!</h1>;
};

return (
<>
<ViolateStaticComponents />
</>
);
}
`,
errors: 2,
},
],
});
Loading