Skip to content

Commit

Permalink
Use eslint-config-stylelint
Browse files Browse the repository at this point in the history
  • Loading branch information
kristerkari committed Nov 13, 2018
1 parent 10b4ef2 commit 60d4e98
Show file tree
Hide file tree
Showing 61 changed files with 436 additions and 130 deletions.
28 changes: 19 additions & 9 deletions babel-jest.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use strict"; // eslint-disable-line
"use strict"; // eslint-disable-line strict

/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/

const crypto = require("crypto");
const fs = require("fs");
Expand All @@ -29,27 +29,34 @@ const createTransformer = options => {
const getBabelRC = filename => {
const paths = [];
let directory = filename;

while (directory !== (directory = path.dirname(directory))) {
if (cache[directory]) {
break;
}

paths.push(directory);
const configFilePath = path.join(directory, BABELRC_FILENAME);

if (fs.existsSync(configFilePath)) {
cache[directory] = fs.readFileSync(configFilePath, "utf8");
break;
}

const configJsFilePath = path.join(directory, BABELRC_JS_FILENAME);

if (fs.existsSync(configJsFilePath)) {
// $FlowFixMe
cache[directory] = JSON.stringify(require(configJsFilePath));
break;
}

const packageJsonFilePath = path.join(directory, PACKAGE_JSON);

if (fs.existsSync(packageJsonFilePath)) {
// $FlowFixMe
const packageJsonFileContents = require(packageJsonFilePath);

if (packageJsonFileContents[BABEL_CONFIG_KEY]) {
cache[directory] = JSON.stringify(
packageJsonFileContents[BABEL_CONFIG_KEY]
Expand All @@ -60,6 +67,7 @@ const createTransformer = options => {
}
}
paths.forEach(directoryPath => (cache[directoryPath] = cache[directory]));

return cache[directory] || "";
};

Expand All @@ -76,6 +84,7 @@ const createTransformer = options => {
canInstrument: true,
getCacheKey(fileData, filename, configString, _ref) {
const instrument = _ref.instrument;

return crypto
.createHash("md5")
.update(THIS_FILE)
Expand All @@ -99,6 +108,7 @@ const createTransformer = options => {
}

const theseOptions = Object.assign({ filename }, options);

if (transformOptions && transformOptions.instrument) {
// theseOptions.auxiliaryCommentBefore = ' istanbul ignore next ';
// Copied from jest-runtime transform.js
Expand Down
7 changes: 4 additions & 3 deletions jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"; // eslint-disable-line
"use strict"; // eslint-disable-line strict

const _ = require("lodash");
const stylelint = require("stylelint");
Expand All @@ -20,7 +20,7 @@ global.testRule = (rule, schema) => {
}
});

describe(schema.ruleName, () => {
describe(`${schema.ruleName}`, () => {
const stylelintConfig = {
plugins: ["./src"],
rules: {
Expand All @@ -42,6 +42,7 @@ global.testRule = (rule, schema) => {

return stylelint.lint(options).then(output => {
expect(output.results[0].warnings).toEqual([]);

if (!schema.fix) {
return;
}
Expand Down Expand Up @@ -152,7 +153,7 @@ global.testConfig = input => {
const invalidOptionWarnings = data.results[0].invalidOptionWarnings;

if (input.valid) {
expect(invalidOptionWarnings.length).toBe(0);
expect(invalidOptionWarnings).toHaveLength(0);
} else {
expect(invalidOptionWarnings[0].text).toBe(input.message);
}
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"babel-preset-jest": "^23.2.0",
"coveralls": "^3.0.2",
"eslint": "^5.8.0",
"eslint-config-stylelint": "^9.0.0",
"eslint-config-stylelint": "^10.0.0",
"eslint-plugin-lodash": "^3.1.0",
"eslint-plugin-sort-requires": "^2.1.0",
"husky": "^1.1.3",
Expand All @@ -49,7 +49,7 @@
"node": ">=6"
},
"eslintConfig": {
"extends": "eslint:recommended",
"extends": ["eslint:recommended", "stylelint"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 6
Expand Down Expand Up @@ -89,7 +89,11 @@
"lodash/no-extra-args": "error",
"lodash/no-unbound-this": "error",
"lodash/unwrap": "error",
"lodash/preferred-alias": "error"
"lodash/preferred-alias": "error",
"node/no-unsupported-features/es-syntax": ["error", {
"version": ">=6.0.0",
"ignores": ["modules"]
}]
}
},
"files": [
Expand Down
1 change: 1 addition & 0 deletions src/rules/at-else-closing-brace-newline-after/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function(expectation, options, context) {
optional: true
}
);

if (!validOptions) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/rules/at-else-closing-brace-space-after/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function(expectation, _, context) {
actual: expectation,
possible: ["always-intermediate", "never-intermediate"]
});

if (!validOptions) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/rules/at-else-empty-line-before/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function(expectation, _, context) {
actual: expectation,
possible: ["never"]
});

if (!validOptions) {
return;
}
Expand All @@ -31,6 +32,7 @@ export default function(expectation, _, context) {

if (context.fix) {
atrule.raws.before = " ";

return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/rules/at-else-if-parentheses-space-before/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function(value, _, context) {
actual: value,
possible: ["always", "never"]
});

if (!validOptions) {
return;
}
Expand All @@ -24,6 +25,7 @@ export default function(value, _, context) {
const replacement = value === "always" ? "if (" : "if(";

const checker = whitespaceChecker("space", value, messages).before;

root.walkAtRules("else", decl => {
// return early if the else-if statement is not surrounded by parentheses
if (!match.test(decl.params)) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/at-extend-no-missing-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const messages = utils.ruleMessages(ruleName, {
export default function(actual) {
return function(root, result) {
const validOptions = utils.validateOptions(result, ruleName, { actual });

if (!validOptions) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/rules/at-function-named-arguments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function(expectation, options) {
optional: true
}
);

if (!validOptions) {
return;
}
Expand Down Expand Up @@ -65,6 +66,7 @@ export default function(expectation, options) {
}

const parts = f.split("/");

return new RegExp(parts[1], parts[2] || "").test(node.value);
});

Expand Down
3 changes: 3 additions & 0 deletions src/rules/at-function-parentheses-space-before/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function(value, _, context) {
actual: value,
possible: ["always", "never"]
});

if (!validOptions) {
return;
}
Expand All @@ -24,9 +25,11 @@ export default function(value, _, context) {
const replacement = value === "always" ? "$1 (" : "$1(";

const checker = whitespaceChecker("space", value, messages).before;

root.walkAtRules("function", decl => {
if (context.fix) {
decl.params = decl.params.replace(match, replacement);

return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/rules/at-function-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function(pattern) {
actual: pattern,
possible: [isRegExp, isString]
});

if (!validOptions) {
return;
}
Expand All @@ -27,6 +28,7 @@ export default function(pattern) {

// Stripping the function of its arguments
const funcName = decl.params.replace(/(\s*?)\((?:\s|\S)*\)/g, "");

if (regexpPattern.test(funcName)) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/rules/at-if-closing-brace-newline-after/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function(expectation, options, context) {
optional: true
}
);

if (!validOptions) {
return;
}
Expand Down Expand Up @@ -66,9 +67,11 @@ export function sassConditionalBraceNLAfterChecker({
options
}) {
const shouldFix = context.fix && (!options || options.disableFix !== true);

function complain(node, message, index, fixValue) {
if (shouldFix) {
node.next().raws.before = fixValue;

return;
}

Expand All @@ -88,6 +91,7 @@ export function sassConditionalBraceNLAfterChecker({
}

const nextNode = atrule.next();

if (!nextNode) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/rules/at-if-closing-brace-space-after/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function(expectation, _, context) {
actual: expectation,
possible: ["always-intermediate", "never-intermediate"]
});

if (!validOptions) {
return;
}
Expand Down Expand Up @@ -54,6 +55,7 @@ export function sassConditionalBraceSpaceAfterChecker({
function complain(node, message, index, fixValue) {
if (context.fix) {
node.next().raws.before = fixValue;

return;
}

Expand Down
1 change: 1 addition & 0 deletions src/rules/at-import-no-partial-leading-underscore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const messages = utils.ruleMessages(ruleName, {
export default function(actual) {
return (root, result) => {
const validOptions = utils.validateOptions(result, ruleName, { actual });

if (!validOptions) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/rules/at-import-partial-extension-blacklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ export const messages = utils.ruleMessages(ruleName, {

export default function(blacklistOption) {
const blacklist = [].concat(blacklistOption);

return (root, result) => {
const validOptions = utils.validateOptions(result, ruleName, {
actual: blacklistOption,
possible: [isString, isRegExp]
});

if (!validOptions) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/rules/at-import-partial-extension-whitelist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ export const messages = utils.ruleMessages(ruleName, {

export default function(whitelistOption) {
const whitelist = [].concat(whitelistOption);

return (root, result) => {
const validOptions = utils.validateOptions(result, ruleName, {
actual: whitelistOption,
possible: [isString, isRegExp]
});

if (!validOptions) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/rules/at-mixin-argumentless-call-parentheses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function(value, _, context) {
actual: value,
possible: ["always", "never"]
});

if (!validOptions) {
return;
}
Expand All @@ -27,6 +28,7 @@ export default function(value, _, context) {
) {
return;
}

// If it is "Always use parens"
if (value === "always" && mixinCall.params.search(/\(/) !== -1) {
return;
Expand All @@ -38,6 +40,7 @@ export default function(value, _, context) {
} else {
mixinCall.params = mixinCall.params.replace(/\s*\([\s\S]*?\)$/, "");
}

return;
}

Expand Down
1 change: 1 addition & 0 deletions src/rules/at-mixin-named-arguments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function(expectation, options) {
optional: true
}
);

if (!validOptions) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/rules/at-mixin-parentheses-space-before/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function(value, _, context) {
actual: value,
possible: ["always", "never"]
});

if (!validOptions) {
return;
}
Expand All @@ -24,9 +25,11 @@ export default function(value, _, context) {
const replacement = value === "always" ? "$1 (" : "$1(";

const checker = whitespaceChecker("space", value, messages).before;

root.walkAtRules("mixin", decl => {
if (context.fix) {
decl.params = decl.params.replace(match, replacement);

return;
}

Expand Down
Loading

0 comments on commit 60d4e98

Please sign in to comment.