diff --git a/change/@boll-core-2020-10-22-10-57-00-dep-detector-improvement.json b/change/@boll-core-2020-10-22-10-57-00-dep-detector-improvement.json new file mode 100644 index 00000000..95c29c99 --- /dev/null +++ b/change/@boll-core-2020-10-22-10-57-00-dep-detector-improvement.json @@ -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" +} diff --git a/change/@boll-rules-core-2020-10-22-10-57-00-dep-detector-improvement.json b/change/@boll-rules-core-2020-10-22-10-57-00-dep-detector-improvement.json new file mode 100644 index 00000000..c5200a11 --- /dev/null +++ b/change/@boll-rules-core-2020-10-22-10-57-00-dep-detector-improvement.json @@ -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" +} diff --git a/change/@boll-rules-external-tools-2020-10-22-10-57-00-dep-detector-improvement.json b/change/@boll-rules-external-tools-2020-10-22-10-57-00-dep-detector-improvement.json new file mode 100644 index 00000000..d23b2f4c --- /dev/null +++ b/change/@boll-rules-external-tools-2020-10-22-10-57-00-dep-detector-improvement.json @@ -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" +} diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 1d099838..04692151 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -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); }); } diff --git a/packages/core/src/rule-registry.ts b/packages/core/src/rule-registry.ts index e64a6598..b7ee7b48 100644 --- a/packages/core/src/rule-registry.ts +++ b/packages/core/src/rule-registry.ts @@ -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 } = {}; diff --git a/packages/core/src/tests/config.test.ts b/packages/core/src/tests/config.test.ts index ecd1bd6e..fa054fa5 100644 --- a/packages/core/src/tests/config.test.ts +++ b/packages/core/src/tests/config.test.ts @@ -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."); +}); diff --git a/packages/core/src/tests/pragma.test.ts b/packages/core/src/tests/pragma.test.ts index 3dda99d5..8312ca89 100644 --- a/packages/core/src/tests/pragma.test.ts +++ b/packages/core/src/tests/pragma.test.ts @@ -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"]); }); }); diff --git a/packages/rules-external-tools/src/tests/eslint-prefer-const-rule.test.ts b/packages/rules-external-tools/src/tests/eslint-prefer-const-rule.test.ts index d3ea59f6..3380f48d 100644 --- a/packages/rules-external-tools/src/tests/eslint-prefer-const-rule.test.ts +++ b/packages/rules-external-tools/src/tests/eslint-prefer-const-rule.test.ts @@ -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(