Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply rule in the order defined in lib/rules/index.js #3923

Merged
merged 2 commits into from Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 29 additions & 11 deletions lib/__tests__/integration.test.js
Expand Up @@ -65,31 +65,49 @@ describe("integration test expecting warnings", () => {
});

it("block-opening-brace-newline-after - string primary option", () => {
expect(result.messages[0].text).toBe(
const error = result.messages.find(
msg => msg.rule === "block-opening-brace-newline-after"
);

expect(error).toBeTruthy();
expect(error.text).toBe(
'Expected newline after "{" (block-opening-brace-newline-after)'
);
expect(result.messages[0].severity).toBe("error");
expect(error.severity).toBe("error");
});

it("declaration-property-unit-blacklist - object primary option", () => {
expect(result.messages[1].text).toBe(
const error = result.messages.find(
msg => msg.rule === "declaration-property-unit-blacklist"
);

expect(error).toBeTruthy();
expect(error.text).toBe(
'Unexpected unit "px" for property "width" (declaration-property-unit-blacklist)'
);
expect(result.messages[1].severity).toBe("error");
expect(error.severity).toBe("error");
});

it("color-no-invalid-hex - true primary option", () => {
expect(result.messages[2].text).toBe("You made a mistake");
expect(result.messages[2].severity).toBe("warning");
expect(result.messages[3].text).toBe("You made a mistake");
expect(result.messages[3].severity).toBe("warning");
const errors = result.messages.filter(
msg => msg.rule === "color-no-invalid-hex"
);

expect(errors).toHaveLength(2);
errors.forEach(error => {
expect(error.text).toBe("You made a mistake");
expect(error.severity).toBe("warning");
});
});

it("function-blacklist - array primary option", () => {
expect(result.messages[4].text).toBe(
'Unexpected function "calc" (function-blacklist)'
const error = result.messages.find(
msg => msg.rule === "function-blacklist"
);
expect(result.messages[4].severity).toBe("error");

expect(error).toBeTruthy();
expect(error.text).toBe('Unexpected function "calc" (function-blacklist)');
expect(error.severity).toBe("error");
});
});

Expand Down
12 changes: 7 additions & 5 deletions lib/__tests__/standalone.test.js
Expand Up @@ -332,14 +332,16 @@ describe("standalone with config locatable from process.cwd not file", () => {
expect(results[0].warnings).toHaveLength(2);
});

it("first correct warning", () => {
it("'block-no-empty' correct warning", () => {
expect(
results[0].warnings[0].text.indexOf("Unexpected empty block")
).not.toBe(-1);
results[0].warnings.find(warn => warn.rule === "block-no-empty")
).toBeTruthy();
});

it("second correct warning", () => {
expect(results[0].warnings[1].text.indexOf("foo")).not.toBe(-1);
it("'plugin/warn-about-foo' correct warning", () => {
expect(
results[0].warnings.find(warn => warn.rule === "plugin/warn-about-foo")
).toBeTruthy();
});
});

Expand Down
7 changes: 6 additions & 1 deletion lib/lintSource.js
Expand Up @@ -7,6 +7,7 @@ const configurationError = require("./utils/configurationError");
const getOsEol = require("./utils/getOsEol");
const path = require("path");
const requireRule = require("./requireRule");
const rulesOrder = require("./rules");

/*:: type postcssResultT = {
processor: {
Expand Down Expand Up @@ -191,7 +192,11 @@ function lintPostcssResult(
// rules down the line.
const performRules = [];

const rules = config.rules ? Object.keys(config.rules) : [];
const rules = config.rules
? Object.keys(config.rules).sort(
(a, b) => rulesOrder.indexOf(a) - rulesOrder.indexOf(b)
)
: [];

rules.forEach(ruleName => {
const ruleFunction =
Expand Down