33
return err.name === "ReactCompilerError";
34
}
35
36
+const DEFAULT_REPORTABLE_LEVELS = new Set([
37
+ ErrorSeverity.InvalidReact,
38
+ ErrorSeverity.InvalidJS,
39
+]);
40
+let reportableLevels = DEFAULT_REPORTABLE_LEVELS;
41
+
42
function isReportableDiagnostic(
43
detail: CompilerErrorDetail
44
): detail is CompilerErrorDetailWithLoc {
39
- let isReportable = false;
40
- switch (detail.severity) {
41
- case ErrorSeverity.InvalidReact:
42
- case ErrorSeverity.InvalidJS:
43
- isReportable = true;
44
- break;
45
- case ErrorSeverity.InvalidConfig:
46
- case ErrorSeverity.Invariant:
47
- case ErrorSeverity.CannotPreserveMemoization:
48
- case ErrorSeverity.Todo:
49
- break;
50
- default:
51
- assertExhaustive(
52
- detail.severity,
53
- `Unhandled error severity \`${detail.severity}\``
54
- );
55
- }
56
-
45
return (
58
- isReportable === true &&
46
+ reportableLevels.has(detail.severity) &&
47
detail.loc != null &&
48
typeof detail.loc !== "symbol"
49
);
71
// Compat with older versions of eslint
72
const sourceCode = context.sourceCode?.text ?? context.getSourceCode().text;
73
const filename = context.filename ?? context.getFilename();
74
+ const userOpts = context.options[0] ?? {};
75
+ if (
76
+ userOpts["reportableLevels"] != null &&
77
+ userOpts["reportableLevels"] instanceof Set
78
+ ) {
79
+ reportableLevels = userOpts["reportableLevels"];
80
+ } else {
81
+ reportableLevels = DEFAULT_REPORTABLE_LEVELS;
82
+ }
83
const options: PluginOptions = {
87
- ...parsePluginOptions(context.options[0] ?? {}),
84
+ ...parsePluginOptions(userOpts),
85
...COMPILER_OPTIONS,
86
};
87