diff --git a/lib/getPostcssResult.js b/lib/getPostcssResult.js index 39a63822b2..902a9d18f5 100644 --- a/lib/getPostcssResult.js +++ b/lib/getPostcssResult.js @@ -16,7 +16,7 @@ const syntaxes /*: { stringify: postcss.stringify } }; -["less", "sass", "scss", "markdown", "html", "styled"].forEach(mod => { +["less", "sass", "scss", "markdown", "html", "styled", "jsx"].forEach(mod => { syntaxes[mod] = importLazy("postcss-" + mod); }); diff --git a/lib/rules/function-whitespace-after/__tests__/index.js b/lib/rules/function-whitespace-after/__tests__/index.js index 0292c330d8..726f400df7 100644 --- a/lib/rules/function-whitespace-after/__tests__/index.js +++ b/lib/rules/function-whitespace-after/__tests__/index.js @@ -61,6 +61,9 @@ testRule(rule, { { code: "a { color: color(rgb(0,0,0)\r\nlightness(50%)) };" }, + { + code: "@import url(example.css) screen;" + }, { code: "$list: (value, value2);$thingTwo: 0px", description: "Sass list ignored" @@ -91,6 +94,12 @@ testRule(rule, { message: messages.expected, line: 1, column: 28 + }, + { + code: "@import url(example.css)screen;", + message: messages.expected, + line: 1, + column: 25 } ] }); @@ -225,3 +234,26 @@ testRule(rule, { } ] }); + +testRule(rule, { + ruleName, + config: ["always"], + skipBasicChecks: true, + syntax: "jsx", + + accept: [ + { + code: "export default ;" + } + ], + + reject: [ + { + code: + "export default ;", + message: messages.expected, + line: 1, + column: 60 + } + ] +}); diff --git a/lib/rules/function-whitespace-after/index.js b/lib/rules/function-whitespace-after/index.js index 8eee8deee5..3080aadb26 100644 --- a/lib/rules/function-whitespace-after/index.js +++ b/lib/rules/function-whitespace-after/index.js @@ -1,5 +1,8 @@ "use strict"; +const _ = require("lodash"); +const atRuleParamIndex = require("../../utils/atRuleParamIndex"); +const declarationValueIndex = require("../../utils/declarationValueIndex"); const isWhitespace = require("../../utils/isWhitespace"); const report = require("../../utils/report"); const ruleMessages = require("../../utils/ruleMessages"); @@ -32,23 +35,21 @@ const rule = function(expectation) { return; } - root.walkDecls(decl => { - const declString = decl.toString(); - + function check(node, value, getIndex) { styleSearch( { - source: declString, + source: value, target: ")", functionArguments: "only" }, match => { - checkClosingParen(declString, match.startIndex, decl); + checkClosingParen(value, match.startIndex + 1, node, getIndex); } ); - }); + } - function checkClosingParen(source, index, node) { - const nextChar = source[index + 1]; + function checkClosingParen(source, index, node, getIndex) { + const nextChar = source[index]; if (expectation === "always") { // Allow for the next character to be a single empty space, // another closing parenthesis, a comma, or the end of the value @@ -58,7 +59,7 @@ const rule = function(expectation) { if (nextChar === "\n") { return; } - if (source.substr(index + 1, 2) === "\r\n") { + if (source.substr(index, 2) === "\r\n") { return; } if (ACCEPTABLE_AFTER_CLOSING_PAREN.has(nextChar)) { @@ -67,7 +68,7 @@ const rule = function(expectation) { report({ message: messages.expected, node, - index: index + 1, + index: getIndex(node) + index, result, ruleName }); @@ -76,13 +77,24 @@ const rule = function(expectation) { report({ message: messages.rejected, node, - index: index + 1, + index: getIndex(node) + index, result, ruleName }); } } } + + root.walkAtRules(/^import$/i, atRule => + check(atRule, atRule.params, atRuleParamIndex) + ); + root.walkDecls(decl => + check( + decl, + _.get(decl, "raws.value.raw", decl.value), + declarationValueIndex + ) + ); }; }; diff --git a/lib/rules/no-missing-end-of-source-newline/__tests__/index.js b/lib/rules/no-missing-end-of-source-newline/__tests__/index.js index 77120b59fb..3adb146b73 100644 --- a/lib/rules/no-missing-end-of-source-newline/__tests__/index.js +++ b/lib/rules/no-missing-end-of-source-newline/__tests__/index.js @@ -106,6 +106,24 @@ a { ] }); +testRule(rule, { + ruleName, + config: [true], + skipBasicChecks: true, + syntax: "jsx", + + accept: [ + { + code: `export default ( + + );` + } + ] +}); + testRule(rule, { ruleName, config: [true], diff --git a/lib/rules/no-missing-end-of-source-newline/index.js b/lib/rules/no-missing-end-of-source-newline/index.js index d4929701f9..d95de9d88d 100644 --- a/lib/rules/no-missing-end-of-source-newline/index.js +++ b/lib/rules/no-missing-end-of-source-newline/index.js @@ -21,7 +21,7 @@ const rule = function(primary, _, context) { eachRoot(root, checkRoot); function checkRoot(root) { - if (root.source.inline) { + if (root.source.inline || root.source.lang === "object-literal") { return; } const rootString = root.source.input.css; diff --git a/lib/utils/declarationValueIndex.js b/lib/utils/declarationValueIndex.js index a6b49bf08e..bd5e1a97c4 100644 --- a/lib/utils/declarationValueIndex.js +++ b/lib/utils/declarationValueIndex.js @@ -1,12 +1,16 @@ /* @flow */ "use strict"; +const _ = require("lodash"); /** * Get the index of a declaration's value */ module.exports = function(decl /*: Object*/) /*: number*/ { - const beforeColon = decl.toString().indexOf(":"); - const afterColon = - decl.raw("between").length - decl.raw("between").indexOf(":"); - return beforeColon + afterColon; + return [ + _.get(decl, "raws.prop.prefix"), + _.get(decl, "raws.prop.raw", decl.prop), + _.get(decl, "raws.prop.suffix"), + _.get(decl, "raws.between", ":"), + _.get(decl, "raws.value.prefix") + ].reduce((count, str) => str ? count + str.length : count, 0); }; diff --git a/package.json b/package.json index 782275c61b..d552aa6b2f 100644 --- a/package.json +++ b/package.json @@ -62,9 +62,10 @@ "normalize-selector": "^0.2.0", "pify": "^3.0.0", "postcss": "^7.0.0", - "postcss-html": "^0.31.0", + "postcss-jsx": "^0.32.0", + "postcss-html": "^0.32.0", "postcss-less": "^2.0.0", - "postcss-markdown": "^0.31.0", + "postcss-markdown": "^0.32.0", "postcss-media-query-parser": "^0.2.3", "postcss-reporter": "^5.0.0", "postcss-resolve-nested-selector": "^0.1.1", @@ -72,8 +73,8 @@ "postcss-sass": "^0.3.0", "postcss-scss": "^2.0.0", "postcss-selector-parser": "^3.1.0", - "postcss-styled": "^0.31.0", - "postcss-syntax": "^0.31.0", + "postcss-styled": "^0.32.0", + "postcss-syntax": "^0.32.0", "postcss-value-parser": "^3.3.0", "resolve-from": "^4.0.0", "signal-exit": "^3.0.2",