Skip to content

Commit

Permalink
Chore: add tests for built-in rules config schema validation (fixes #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Mar 14, 2021
1 parent d8ea601 commit 7f9ae78
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions tests/lib/cascading-config-array-factory.js
Expand Up @@ -1834,6 +1834,101 @@ describe("CascadingConfigArrayFactory", () => {
});
});
});

describe("when there is an invalid option for a bult-in rule", () => {

const root = path.join(systemTempDir, "eslint/cli-engine/cascading-config-array-factory");
const filePath = path.join(root, "foo.js");

/** @type {Map<string, Rule>} */
const builtInRules = new Map();

builtInRules.set("dot-location", {
meta: {
schema: [
{
enum: ["object", "property"]
}
]
},
create() {
return {};
}
});

describe("in '.eslintrc.json' file", () => {
const files = {
".eslintrc.json": JSON.stringify({
root: true,
rules: {
"dot-location": ["error", "foo"]
}
})
};
const { prepare, cleanup } = createCustomTeardown({ cwd: root, files });

beforeEach(prepare);
afterEach(cleanup);

it("should throw a configuration error", () => {
const factory = new CascadingConfigArrayFactory({
cwd: root,
builtInRules
});

assert.throws(
() => factory.getConfigArrayForFile(filePath),
/Configuration for rule "dot-location" is invalid/u
);
});
});

describe("in 'baseConfig'", () => {
const baseConfig = {
rules: {
"dot-location": ["error", {}]
}
};

it("should throw a configuration error", () => {

const factory = new CascadingConfigArrayFactory({
cwd: root,
builtInRules,
useEslintrc: false,
baseConfig
});

assert.throws(
() => factory.getConfigArrayForFile(filePath),
/Configuration for rule "dot-location" is invalid/u
);
});
});

describe("in 'cliConfig'", () => {
const cliConfig = {
rules: {
"dot-location": ["error", "object", "extra"]
}
};

it("should throw a configuration error", () => {

const factory = new CascadingConfigArrayFactory({
cwd: root,
builtInRules,
useEslintrc: false,
cliConfig
});

assert.throws(
() => factory.getConfigArrayForFile(filePath),
/Configuration for rule "dot-location" is invalid/u
);
});
});
});
});

describe("'clearCache()' method should clear cache.", () => {
Expand Down

0 comments on commit 7f9ae78

Please sign in to comment.