Skip to content

Commit

Permalink
Apply rule in the order defined in lib/rules/index.js (#3923)
Browse files Browse the repository at this point in the history
  • Loading branch information
gucong3000 authored and hudochenkov committed Apr 3, 2019
1 parent cb9791e commit 35c3f5a
Show file tree
Hide file tree
Showing 6 changed files with 2,222 additions and 2,177 deletions.
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

0 comments on commit 35c3f5a

Please sign in to comment.