зеркало из https://github.com/microsoft/boll.git
In-config options for rules
This commit is contained in:
Родитель
6611dd1702
Коммит
80d8e1afc9
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"type": "minor",
|
||||
"comment": "in-config options for rules",
|
||||
"packageName": "@boll/core",
|
||||
"email": "jdh@microsoft.com",
|
||||
"dependentChangeType": "patch",
|
||||
"date": "2020-10-22T17:56:43.845Z"
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"type": "patch",
|
||||
"comment": "TransitiveDependencyDetector option to allow devDependencies",
|
||||
"packageName": "@boll/rules-core",
|
||||
"email": "jdh@microsoft.com",
|
||||
"dependentChangeType": "patch",
|
||||
"date": "2020-10-22T17:56:54.928Z"
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"type": "minor",
|
||||
"comment": "TransitiveDependencyDetector option to allow devDependencies",
|
||||
"packageName": "@boll/rules-external-tools",
|
||||
"email": "jdh@microsoft.com",
|
||||
"dependentChangeType": "patch",
|
||||
"date": "2020-10-22T17:57:00.021Z"
|
||||
}
|
|
@ -23,7 +23,9 @@ export class Config {
|
|||
const glob = ruleSetConfig.fileLocator;
|
||||
glob.exclude = exclude;
|
||||
glob.include = ruleSetConfig.include || [];
|
||||
const checks = (ruleSetConfig.checks || []).map(check => this.ruleRegistry.get(check.rule)(this.logger));
|
||||
const checks = (ruleSetConfig.checks || []).map(check =>
|
||||
this.ruleRegistry.get(check.rule)(this.logger, check.options)
|
||||
);
|
||||
return new RuleSet(glob, checks);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { Logger } from "./logger";
|
||||
import { PackageRule } from "./types";
|
||||
|
||||
export type RuleDefinition = (logger: Logger) => PackageRule;
|
||||
export type RuleDefinition = (logger: Logger, options?: {}) => PackageRule;
|
||||
|
||||
export class RuleRegistry {
|
||||
public registrations: { [name: string]: RuleDefinition } = {};
|
||||
|
||||
|
|
|
@ -52,3 +52,19 @@ test("should apply exclude/include across extended config", () => {
|
|||
const suite = config.buildSuite();
|
||||
assert.deepStrictEqual(suite.ruleSets[0].fileGlob.exclude, ["testme"]);
|
||||
});
|
||||
|
||||
test("gives options to factory function", () => {
|
||||
const configRegistry = new ConfigRegistry();
|
||||
const ruleRegistry = new RuleRegistry();
|
||||
let calledWithCorrectArgs = false;
|
||||
ruleRegistry.register("foo", (l: any, options: any) => {
|
||||
if (options && options.bar === "baz") {
|
||||
calledWithCorrectArgs = true;
|
||||
}
|
||||
return new FakeRule();
|
||||
});
|
||||
const config = new Config(configRegistry, ruleRegistry, NullLogger);
|
||||
config.load({ ruleSets: [{ fileLocator: new FakeGlob(), checks: [{ rule: "foo", options: { bar: "baz" } }] }] });
|
||||
config.buildSuite();
|
||||
assert.ok(calledWithCorrectArgs, "Rule factory should have been invoked with correct args when creating suite.");
|
||||
});
|
||||
|
|
|
@ -7,14 +7,14 @@ export const test: any = baretest("Source detector");
|
|||
|
||||
test("should keep track of a disabled rule in a FileContext", async () => {
|
||||
await inFixtureDir("standalone-source-files", __dirname, async cwd => {
|
||||
const sut = await getSourceFile(cwd, "simple-disable.ts", new Package({},{}));
|
||||
const sut = await getSourceFile(cwd, "simple-disable.ts", new Package({}, {}));
|
||||
assert.deepStrictEqual(sut.ignoredChecks, ["MadeUpCheckName"]);
|
||||
});
|
||||
});
|
||||
|
||||
test("should keep track of multiple disabled rules in a FileContext", async () => {
|
||||
await inFixtureDir("standalone-source-files", __dirname, async cwd => {
|
||||
const sut = await getSourceFile(cwd, "multiple-disable.ts", new Package({},{}));
|
||||
const sut = await getSourceFile(cwd, "multiple-disable.ts", new Package({}, {}));
|
||||
assert.deepStrictEqual(sut.ignoredChecks, ["MadeUpCheckName", "AlsoMadeUpName"]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,7 +18,9 @@ test("Should succeed because prefer-const rule is set to 'error'", async () => {
|
|||
test("Should fail because prefer-const rule is set to 'off'", async () => {
|
||||
await inFixtureDir("configs/eslint/prefer-const/prefer-const-off", __dirname, async () => {
|
||||
const sut = new ESLintPreferConstRule(NullLogger);
|
||||
const results = await sut.check(await getSourceFile(asBollDirectory("."), "prefer-const-off.ts", new Package({}, {})));
|
||||
const results = await sut.check(
|
||||
await getSourceFile(asBollDirectory("."), "prefer-const-off.ts", new Package({}, {}))
|
||||
);
|
||||
assert.strictEqual(results.length, 1);
|
||||
assert.strictEqual(results[0].status, ResultStatus.failure);
|
||||
assert.strictEqual(
|
||||
|
|
Загрузка…
Ссылка в новой задаче