diff --git a/packages/stylelint-config-wordpress/__tests__/functions-invalid.css b/packages/stylelint-config-wordpress/__tests__/functions-invalid.css new file mode 100644 index 0000000000000..33a93985335cf --- /dev/null +++ b/packages/stylelint-config-wordpress/__tests__/functions-invalid.css @@ -0,0 +1,5 @@ +/* function-name-case */ + +a { + width: Calc(5% - 10em); +} diff --git a/packages/stylelint-config-wordpress/__tests__/functions-valid.css b/packages/stylelint-config-wordpress/__tests__/functions-valid.css new file mode 100644 index 0000000000000..8219b38b2005c --- /dev/null +++ b/packages/stylelint-config-wordpress/__tests__/functions-valid.css @@ -0,0 +1,7 @@ +/* function-name-case */ + +a { + width: calc(5% - 10em); + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#1e8cbe", endColorstr="#0074a2", GradientType=0); + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); +} diff --git a/packages/stylelint-config-wordpress/__tests__/functions.js b/packages/stylelint-config-wordpress/__tests__/functions.js new file mode 100644 index 0000000000000..b7cb3b65dbd12 --- /dev/null +++ b/packages/stylelint-config-wordpress/__tests__/functions.js @@ -0,0 +1,84 @@ +"use strict" + +const fs = require("fs") +const config = require("../") +const stylelint = require("stylelint") + +const validCss = fs.readFileSync("./__tests__/functions-valid.css", "utf-8") +const invalidCss = fs.readFileSync("./__tests__/functions-invalid.css", "utf-8") + +describe("flags no warnings with valid functions css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: validCss, + config, + }) + }) + + it("did not error", () => { + return result.then(data => ( + expect(data.errored).toBeFalsy() + )) + }) + + it("flags no warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(0) + )) + }) +}) + +describe("flags warnings with invalid functions css", () => { + let result + + beforeEach(() => { + result = stylelint.lint({ + code: invalidCss, + config, + }) + }) + + it("did error", () => { + return result.then(data => ( + expect(data.errored).toBeTruthy() + )) + }) + + it("flags three warnings", () => { + return result.then(data => ( + expect(data.results[0].warnings.length).toBe(1) + )) + }) + + it("correct first warning text", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].text).toBe("Expected \"Calc\" to be \"calc\" (function-name-case)") + )) + }) + + it("correct first warning rule flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].rule).toBe("function-name-case") + )) + }) + + it("correct first warning severity flagged", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].severity).toBe("error") + )) + }) + + it("correct first warning line number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].line).toBe(4) + )) + }) + + it("correct first warning column number", () => { + return result.then(data => ( + expect(data.results[0].warnings[0].column).toBe(9) + )) + }) +}) diff --git a/packages/stylelint-config-wordpress/index.js b/packages/stylelint-config-wordpress/index.js index 13106e539770b..c71d12121649c 100644 --- a/packages/stylelint-config-wordpress/index.js +++ b/packages/stylelint-config-wordpress/index.js @@ -40,7 +40,9 @@ module.exports = { "function-comma-space-before": "never", "function-linear-gradient-no-nonstandard-direction": true, "function-max-empty-lines": 1, - "function-name-case": "lower", + "function-name-case": [ "lower", { + ignoreFunctions: ["/^DXImageTransform.Microsoft.*$/"], + } ], "function-parentheses-space-inside": "never", "function-url-quotes": "never", "function-whitespace-after": "always",