This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
766 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import {test} from "rome"; | ||
import {LintRequest, LintResult, lint, lintRuleNames} from "@internal/compiler"; | ||
import {ProjectConfig, createDefaultProjectConfig} from "@internal/project"; | ||
import {parseJS} from "@internal/js-parser"; | ||
|
||
function createLintTransformOptions( | ||
sourceText: string, | ||
mutateConfig: (config: ProjectConfig) => ProjectConfig, | ||
): LintRequest { | ||
return { | ||
applySafeFixes: false, | ||
suppressionExplanation: "", | ||
sourceText, | ||
ast: parseJS({ | ||
path: "unknown", | ||
input: sourceText, | ||
}), | ||
options: {}, | ||
project: { | ||
config: mutateConfig(createDefaultProjectConfig()), | ||
directory: undefined, | ||
}, | ||
}; | ||
} | ||
|
||
test( | ||
"disabledLintRules single", | ||
async (t) => { | ||
function hasUndeclaredDiag(res: LintResult): boolean { | ||
for (const diag of res.diagnostics) { | ||
if (diag.description.category === "lint/js/noUndeclaredVariables") { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
// Make sure when it's not disabled the diagnostic is present | ||
const res = await lint( | ||
createLintTransformOptions("foo;", (config) => config), | ||
); | ||
t.true(hasUndeclaredDiag(res)); | ||
|
||
// Make sure when it's not disabled the diagnostic it is not present | ||
const res2 = await lint( | ||
createLintTransformOptions( | ||
"foo;", | ||
(config) => ({ | ||
...config, | ||
lint: { | ||
...config.lint, | ||
disabledRules: ["js/noUndeclaredVariables"], | ||
}, | ||
}), | ||
), | ||
); | ||
t.false(hasUndeclaredDiag(res2)); | ||
}, | ||
); | ||
|
||
test( | ||
"disabledLintRules all rules", | ||
async (t) => { | ||
const res = await lint( | ||
createLintTransformOptions( | ||
"foo;", | ||
(config) => ({ | ||
...config, | ||
lint: { | ||
...config.lint, | ||
disabledRules: lintRuleNames, | ||
}, | ||
}), | ||
), | ||
); | ||
t.is(res.diagnostics.length, 0); | ||
}, | ||
); | ||
|
||
test( | ||
"format disabled", | ||
async (t) => { | ||
const code = "wacky\n\tformatting( yes,\nok );"; | ||
const res = await lint( | ||
createLintTransformOptions( | ||
code, | ||
(config) => ({ | ||
...config, | ||
format: { | ||
...config.format, | ||
enabled: false, | ||
}, | ||
}), | ||
), | ||
); | ||
t.is(res.src, code); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.