You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Renames the `recommended` property on LintRule to `preset`, to allow exporting rules for different presets. For now the `Recommended` and `RecommendedLatest` presets are the same, but in the next PR I will enable more rules for the latest preset.
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts
+44-30Lines changed: 44 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -669,6 +669,21 @@ export enum ErrorCategory {
669
669
FBT='FBT',
670
670
}
671
671
672
+
exportenumLintRulePreset{
673
+
/**
674
+
* Rules that are stable and included in the `recommended` preset.
675
+
*/
676
+
Recommended='recommended',
677
+
/**
678
+
* Rules that are more experimental and only included in the `recommended-latest` preset.
679
+
*/
680
+
RecommendedLatest='recommended-latest',
681
+
/**
682
+
* Rules that are disabled.
683
+
*/
684
+
Off='off',
685
+
}
686
+
672
687
exporttypeLintRule={
673
688
// Stores the category the rule corresponds to, used to filter errors when reporting
674
689
category: ErrorCategory;
@@ -689,15 +704,14 @@ export type LintRule = {
689
704
description: string;
690
705
691
706
/**
692
-
* If true, this rule will automatically appear in the default, "recommended" ESLint
693
-
* rule set. Otherwise it will be part of an `allRules` export that developers can
694
-
* use to opt-in to showing output of all possible rules.
707
+
* Configures the preset in which the rule is enabled. If 'off', the rule will not be included in
708
+
* any preset.
695
709
*
696
710
* NOTE: not all validations are enabled by default! Setting this flag only affects
697
711
* whether a given rule is part of the recommended set. The corresponding validation
698
712
* also should be enabled by default if you want the error to actually show up!
699
713
*/
700
-
recommended: boolean;
714
+
preset: LintRulePreset;
701
715
};
702
716
703
717
constRULE_NAME_PATTERN=/^[a-z]+(-[a-z]+)*$/;
@@ -720,7 +734,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
720
734
name: 'automatic-effect-dependencies',
721
735
description:
722
736
'Verifies that automatic effect dependencies are compiled if opted-in',
723
-
recommended: false,
737
+
preset: LintRulePreset.Off,
724
738
};
725
739
}
726
740
caseErrorCategory.CapitalizedCalls: {
@@ -730,7 +744,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
730
744
name: 'capitalized-calls',
731
745
description:
732
746
'Validates against calling capitalized functions/methods instead of using JSX',
733
-
recommended: false,
747
+
preset: LintRulePreset.Off,
734
748
};
735
749
}
736
750
caseErrorCategory.Config: {
@@ -739,7 +753,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
739
753
severity: ErrorSeverity.Error,
740
754
name: 'config',
741
755
description: 'Validates the compiler configuration options',
742
-
recommended: true,
756
+
preset: LintRulePreset.Recommended,
743
757
};
744
758
}
745
759
caseErrorCategory.EffectDependencies: {
@@ -748,7 +762,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
748
762
severity: ErrorSeverity.Error,
749
763
name: 'memoized-effect-dependencies',
750
764
description: 'Validates that effect dependencies are memoized',
751
-
recommended: false,
765
+
preset: LintRulePreset.Off,
752
766
};
753
767
}
754
768
caseErrorCategory.EffectDerivationsOfState: {
@@ -758,7 +772,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
758
772
name: 'no-deriving-state-in-effects',
759
773
description:
760
774
'Validates against deriving values from state in an effect',
761
-
recommended: false,
775
+
preset: LintRulePreset.Off,
762
776
};
763
777
}
764
778
caseErrorCategory.EffectSetState: {
@@ -768,7 +782,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
768
782
name: 'set-state-in-effect',
769
783
description:
770
784
'Validates against calling setState synchronously in an effect, which can lead to re-renders that degrade performance',
771
-
recommended: true,
785
+
preset: LintRulePreset.Recommended,
772
786
};
773
787
}
774
788
caseErrorCategory.ErrorBoundaries: {
@@ -778,7 +792,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
778
792
name: 'error-boundaries',
779
793
description:
780
794
'Validates usage of error boundaries instead of try/catch for errors in child components',
781
-
recommended: true,
795
+
preset: LintRulePreset.Recommended,
782
796
};
783
797
}
784
798
caseErrorCategory.Factories: {
@@ -789,7 +803,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
789
803
description:
790
804
'Validates against higher order functions defining nested components or hooks. '+
791
805
'Components and hooks should be defined at the module level',
792
-
recommended: true,
806
+
preset: LintRulePreset.Recommended,
793
807
};
794
808
}
795
809
caseErrorCategory.FBT: {
@@ -798,7 +812,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
798
812
severity: ErrorSeverity.Error,
799
813
name: 'fbt',
800
814
description: 'Validates usage of fbt',
801
-
recommended: false,
815
+
preset: LintRulePreset.Off,
802
816
};
803
817
}
804
818
caseErrorCategory.Fire: {
@@ -807,7 +821,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
807
821
severity: ErrorSeverity.Error,
808
822
name: 'fire',
809
823
description: 'Validates usage of `fire`',
810
-
recommended: false,
824
+
preset: LintRulePreset.Off,
811
825
};
812
826
}
813
827
caseErrorCategory.Gating: {
@@ -817,7 +831,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
817
831
name: 'gating',
818
832
description:
819
833
'Validates configuration of [gating mode](https://react.dev/reference/react-compiler/gating)',
820
-
recommended: true,
834
+
preset: LintRulePreset.Recommended,
821
835
};
822
836
}
823
837
caseErrorCategory.Globals: {
@@ -828,7 +842,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
828
842
description:
829
843
'Validates against assignment/mutation of globals during render, part of ensuring that '+
830
844
'[side effects must render outside of render](https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)',
831
-
recommended: true,
845
+
preset: LintRulePreset.Recommended,
832
846
};
833
847
}
834
848
caseErrorCategory.Hooks: {
@@ -842,7 +856,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
842
856
* We need to dedeupe these (moving the remaining bits into the compiler) and then enable
843
857
* this rule.
844
858
*/
845
-
recommended: false,
859
+
preset: LintRulePreset.Off,
846
860
};
847
861
}
848
862
caseErrorCategory.Immutability: {
@@ -852,7 +866,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
852
866
name: 'immutability',
853
867
description:
854
868
'Validates against mutating props, state, and other values that [are immutable](https://react.dev/reference/rules/components-and-hooks-must-be-pure#props-and-state-are-immutable)',
855
-
recommended: true,
869
+
preset: LintRulePreset.Recommended,
856
870
};
857
871
}
858
872
caseErrorCategory.Invariant: {
@@ -861,7 +875,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
861
875
severity: ErrorSeverity.Error,
862
876
name: 'invariant',
863
877
description: 'Internal invariants',
864
-
recommended: false,
878
+
preset: LintRulePreset.Off,
865
879
};
866
880
}
867
881
caseErrorCategory.PreserveManualMemo: {
@@ -873,7 +887,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
873
887
'Validates that existing manual memoized is preserved by the compiler. '+
874
888
'React Compiler will only compile components and hooks if its inference '+
875
889
'[matches or exceeds the existing manual memoization](https://react.dev/learn/react-compiler/introduction#what-should-i-do-about-usememo-usecallback-and-reactmemo)',
876
-
recommended: true,
890
+
preset: LintRulePreset.Recommended,
877
891
};
878
892
}
879
893
caseErrorCategory.Purity: {
@@ -883,7 +897,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
883
897
name: 'purity',
884
898
description:
885
899
'Validates that [components/hooks are pure](https://react.dev/reference/rules/components-and-hooks-must-be-pure) by checking that they do not call known-impure functions',
886
-
recommended: true,
900
+
preset: LintRulePreset.Recommended,
887
901
};
888
902
}
889
903
caseErrorCategory.Refs: {
@@ -893,7 +907,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
893
907
name: 'refs',
894
908
description:
895
909
'Validates correct usage of refs, not reading/writing during render. See the "pitfalls" section in [`useRef()` usage](https://react.dev/reference/react/useRef#usage)',
896
-
recommended: true,
910
+
preset: LintRulePreset.Recommended,
897
911
};
898
912
}
899
913
caseErrorCategory.RenderSetState: {
@@ -903,7 +917,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
903
917
name: 'set-state-in-render',
904
918
description:
905
919
'Validates against setting state during render, which can trigger additional renders and potential infinite render loops',
906
-
recommended: true,
920
+
preset: LintRulePreset.Recommended,
907
921
};
908
922
}
909
923
caseErrorCategory.StaticComponents: {
@@ -913,7 +927,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
913
927
name: 'static-components',
914
928
description:
915
929
'Validates that components are static, not recreated every render. Components that are recreated dynamically can reset state and trigger excessive re-rendering',
916
-
recommended: true,
930
+
preset: LintRulePreset.Recommended,
917
931
};
918
932
}
919
933
caseErrorCategory.Suppression: {
@@ -922,7 +936,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
922
936
severity: ErrorSeverity.Error,
923
937
name: 'rule-suppression',
924
938
description: 'Validates against suppression of other rules',
925
-
recommended: false,
939
+
preset: LintRulePreset.Off,
926
940
};
927
941
}
928
942
caseErrorCategory.Syntax: {
@@ -931,7 +945,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
931
945
severity: ErrorSeverity.Error,
932
946
name: 'syntax',
933
947
description: 'Validates against invalid syntax',
934
-
recommended: false,
948
+
preset: LintRulePreset.Off,
935
949
};
936
950
}
937
951
caseErrorCategory.Todo: {
@@ -940,7 +954,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
940
954
severity: ErrorSeverity.Hint,
941
955
name: 'todo',
942
956
description: 'Unimplemented features',
943
-
recommended: false,
957
+
preset: LintRulePreset.Off,
944
958
};
945
959
}
946
960
caseErrorCategory.UnsupportedSyntax: {
@@ -950,7 +964,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
950
964
name: 'unsupported-syntax',
951
965
description:
952
966
'Validates against syntax that we do not plan to support in React Compiler',
953
-
recommended: true,
967
+
preset: LintRulePreset.Recommended,
954
968
};
955
969
}
956
970
caseErrorCategory.UseMemo: {
@@ -960,7 +974,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
960
974
name: 'use-memo',
961
975
description:
962
976
'Validates usage of the useMemo() hook against common mistakes. See [`useMemo()` docs](https://react.dev/reference/react/useMemo) for more information.',
963
-
recommended: true,
977
+
preset: LintRulePreset.Recommended,
964
978
};
965
979
}
966
980
caseErrorCategory.IncompatibleLibrary: {
@@ -970,7 +984,7 @@ function getRuleForCategoryImpl(category: ErrorCategory): LintRule {
970
984
name: 'incompatible-library',
971
985
description:
972
986
'Validates against usage of libraries which are incompatible with memoization (manual or automatic)',
0 commit comments