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

Update to PostCSS@6 #2561

Merged
merged 7 commits into from
Jun 30, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/__tests__/defaultSeverity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ it("`defaultSeverity` option set to warning", () => {
"block-no-empty": true,
},
}
return postcssPlugin.process("a {}", config).then(result => {
return postcssPlugin.process("a {}", {}, config).then(result => {
const warnings = result.warnings()
expect(warnings.length).toBe(1)
expect(warnings[0].text.indexOf("block-no-empty")).not.toBe(-1)
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/ignoreDisables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("ignoreDisables with postcssPlugins", () => {
let result

beforeEach(() => {
return postcssPlugin.process(css, {
return postcssPlugin.process(css, {}, {
config,
ignoreDisables: true,
}).then(data => result = data)
Expand Down
12 changes: 6 additions & 6 deletions lib/__tests__/postcssPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ it("`configFile` option with absolute path", () => {
const config = {
configFile: path.join(__dirname, "fixtures/config-block-no-empty.json"),
}
return postcssPlugin.process("a {}", config).then(postcssResult => {
return postcssPlugin.process("a {}", {}, config).then(postcssResult => {
const warnings = postcssResult.warnings()
expect(warnings.length).toBe(1)
expect(warnings[0].text.indexOf("block-no-empty")).not.toBe(-1)
})
})

it("`configFile` with bad path", () => {
return postcssPlugin.process("a {}", { configFile: "./herby.json" }).then(() => {
return postcssPlugin.process("a {}", {}, { configFile: "./herby.json" }).then(() => {
throw new Error("should not have succeeded")
}).catch(err => {
expect(err.code).toBe("ENOENT")
Expand All @@ -35,7 +35,7 @@ it("`configFile` option without rules", () => {
const config = {
configFile: path.join(__dirname, "fixtures/config-without-rules.json"),
}
return postcssPlugin.process("a {}", config).then(() => {
return postcssPlugin.process("a {}", {}, config).then(() => {
throw new Error("should not have succeeded")
}).catch(err => {
expect(err).toEqual(configurationError("No rules found within configuration. Have you provided a \"rules\" property?"))
Expand All @@ -47,7 +47,7 @@ it("`configFile` option with undefined rule", () => {
configFile: path.join(__dirname, "fixtures/config-with-undefined-rule.json"),
}
const ruleName = "unknown-rule"
return postcssPlugin.process("a {}", config).then(() => {
return postcssPlugin.process("a {}", {}, config).then(() => {
throw new Error("should not have succeeded")
}).catch(err => {
expect(err).toEqual(configurationError(`Undefined rule ${ruleName}`))
Expand All @@ -62,7 +62,7 @@ it("`ignoreFiles` options is not empty and file ignored", () => {
ignoreFiles: "**/foo.css",
from: "foo.css",
}
return postcssPlugin.process("a {}", config).then(postcssResult => {
return postcssPlugin.process("a {}", {}, config).then(postcssResult => {
expect(postcssResult.stylelint.ignored).toBeTruthy()
})
})
Expand All @@ -75,7 +75,7 @@ it("`ignoreFiles` options is not empty and file not ignored", () => {
ignoreFiles: "**/bar.css",
from: "foo.css",
}
return postcssPlugin.process("a {}", config).then(postcssResult => {
return postcssPlugin.process("a {}", {}, config).then(postcssResult => {
expect(postcssResult.stylelint.ignored).toBeFalsy()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ testRule(rule, {
}, {
code: ":root {\n --x { color: pink; };\n --y { color: red; };\n }",
description: "Allow a trailing semicolon after the closing brace of a block",
}, {
code: ":root {\n --x { color: pink; } ;\n --y { color: red; };\n }",
description: "Allow a spaced trailing semicolon after the closing brace of an at-apply block",
}, {
code: ".foo {\n --my-theme: { color: red; };\n --toolbar-theme: { color: green; };\n }",
description: "Make sure trailing semicolon works well for blocks outside :root",
Expand Down Expand Up @@ -83,10 +86,10 @@ testRule(rule, {
line: 1,
column: 6,
}, {
code: ":root {\n --x { color: pink; } ;\n --y { color: red; };\n }",
code: ":root {\n --x { color: pink; } ; \n --y { color: red; };\n }",
message: messages.expectedAfter(),
line: 2,
column: 22,
column: 24,
}, {
code: ":root {\n --x { color: pink; }; \n --y { color: red; };\n }",
message: messages.expectedAfter(),
Expand Down
22 changes: 13 additions & 9 deletions lib/rules/no-extra-semicolons/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict"

const hasEmptyBlock = require("../../utils/hasEmptyBlock")
const isCustomPropertySet = require("../../utils/isCustomPropertySet")
const report = require("../../utils/report")
const ruleMessages = require("../../utils/ruleMessages")
Expand Down Expand Up @@ -59,11 +58,6 @@ const rule = function (actual) {
if (rawBeforeNode && rawBeforeNode.trim().length !== 0) {
let allowedSemi = 0

// Forbid semicolon before first custom properties sets
if (isCustomPropertySet(node) && node.parent.index(node) > 0) {
allowedSemi = 1
}

const next = node.next()

// Ignore semicolon before comment if next node is custom properties sets or comment
Expand Down Expand Up @@ -93,18 +87,28 @@ const rule = function (actual) {
const rawAfterNode = node.raws.after

if (rawAfterNode && rawAfterNode.trim().length !== 0) {
styleSearch({ source: rawAfterNode, target: ";" }, (match) => {
const index = getOffsetByNode(node) + node.toString().length - 1 - rawAfterNode.length + match.startIndex

complain(index)
})
}

const rawOwnSemicolon = node.raws.ownSemicolon

if (rawOwnSemicolon) {
let allowedSemi = 0

if (!hasEmptyBlock(node) && isCustomPropertySet(node.nodes[node.nodes.length - 1])) {
if (isCustomPropertySet(node)) {
allowedSemi = 1
}

styleSearch({ source: rawAfterNode, target: ";" }, (match, count) => {
styleSearch({ source: rawOwnSemicolon, target: ";" }, (match, count) => {
if (count === allowedSemi) {
return
}

const index = getOffsetByNode(node) + node.toString().length - 1 - rawAfterNode.length + match.startIndex
const index = getOffsetByNode(node) + node.toString().length - rawOwnSemicolon.length + match.startIndex
complain(index)
})
}
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"node": ">=4.2.1"
},
"dependencies": {
"autoprefixer": "^6.0.0",
"autoprefixer": "^7.0.0",
"balanced-match": "^0.4.0",
"chalk": "^1.1.1",
"cosmiconfig": "^2.1.1",
Expand All @@ -57,19 +57,19 @@
"micromatch": "^2.3.11",
"normalize-selector": "^0.2.0",
"pify": "^2.3.0",
"postcss": "^5.0.20",
"postcss": "^6.0.4",
"postcss-less": "^0.14.0",
"postcss-media-query-parser": "^0.2.0",
"postcss-reporter": "^3.0.0",
"postcss-reporter": "^4.0.0",
"postcss-resolve-nested-selector": "^0.1.1",
"postcss-scss": "^0.4.0",
"postcss-scss": "^1.0.0",
"postcss-selector-parser": "^2.1.1",
"postcss-value-parser": "^3.1.1",
"resolve-from": "^3.0.0",
"specificity": "^0.3.0",
"string-width": "^2.0.0",
"style-search": "^0.1.0",
"sugarss": "^0.2.0",
"sugarss": "^1.0.0",
"svg-tags": "^1.0.0",
"table": "^4.0.1"
},
Expand All @@ -88,8 +88,8 @@
"jest": "^20.0.1",
"npm-run-all": "^4.0.0",
"npmpub": "^3.0.1",
"postcss-import": "^9.0.0",
"postcss-safe-parser": "^2.0.0",
"postcss-import": "^10.0.0",
"postcss-safe-parser": "^3.0.0",
"remark-cli": "^3.0.0",
"remark-preset-lint-consistent": "^2.0.0",
"remark-preset-lint-recommended": "^2.0.0",
Expand Down