Skip to content

Commit

Permalink
Adhere to the new lint rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed May 6, 2020
1 parent 9b3b8b6 commit 8c10b0a
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 312 deletions.
24 changes: 11 additions & 13 deletions jest-setup.js
@@ -1,3 +1,5 @@
/* eslint-disable jest/no-standalone-expect */

"use strict";

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

// eslint-disable-next-line jest/valid-describe
describe(`${schema.ruleName}`, () => {
const stylelintConfig = {
plugins: ["./src"],
Expand Down Expand Up @@ -49,13 +50,11 @@ global.testRule = (rule, schema) => {
}

// Check the fix
return stylelint
.lint(Object.assign({ fix: true }, options))
.then(output2 => {
const fixedCode = getOutputCss(output2);
return stylelint.lint({ fix: true, ...options }).then(output2 => {
const fixedCode = getOutputCss(output2);

expect(fixedCode).toBe(testCase.code);
});
expect(fixedCode).toBe(testCase.code);
});
});
});
});
Expand Down Expand Up @@ -104,20 +103,19 @@ global.testRule = (rule, schema) => {
}

// Check the fix
return stylelint
.lint(Object.assign({ fix: true }, options))
.then(output2 => {
const fixedCode = getOutputCss(output2);
return stylelint.lint({ fix: true, ...options }).then(output2 => {
const fixedCode = getOutputCss(output2);

expect(fixedCode).toBe(testCase.fixed);
});
expect(fixedCode).toBe(testCase.fixed);
});
});
});
});
});
}
});
};
/* eslint-enable jest/no-standalone-expect */

function getOutputCss(output) {
const result = output.results[0]._postcssResult;
Expand Down
4 changes: 2 additions & 2 deletions src/rules/at-each-key-value-single-line/index.js
Expand Up @@ -88,9 +88,9 @@ function didCallMapGet(map_decl) {
function mapName(map_decl) {
if (didCallMapKeys(map_decl)) {
return map_decl.match(/map-keys\((.*)\)/)[1];
} else {
return map_decl;
}

return map_decl;
}

// Returns the parameters of a map-get call
Expand Down
6 changes: 2 additions & 4 deletions src/rules/at-if-closing-brace-newline-after/index.js
Expand Up @@ -111,10 +111,8 @@ function sassConditionalBraceNLAfterChecker({
if (hasNewLinesBeforeNext) {
complain(atrule, messages.rejected, reportIndex, " ");
}
} else {
if (!hasNewLinesBeforeNext) {
complain(atrule, messages.expected, reportIndex, context.newline);
}
} else if (!hasNewLinesBeforeNext) {
complain(atrule, messages.expected, reportIndex, context.newline);
}
}
});
Expand Down
12 changes: 5 additions & 7 deletions src/rules/at-rule-conditional-no-parentheses/index.js
Expand Up @@ -57,13 +57,11 @@ function rule(primary, _unused, context) {
report(atrule, result);
}
}
} else {
if (atrule.params.trim().match(/^\(.*\)$/)) {
if (context.fix) {
fix(atrule);
} else {
report(atrule, result);
}
} else if (atrule.params.trim().match(/^\(.*\)$/)) {
if (context.fix) {
fix(atrule);
} else {
report(atrule, result);
}
}
});
Expand Down
26 changes: 14 additions & 12 deletions src/rules/at-rule-no-unknown/__tests__/index.js
Expand Up @@ -204,18 +204,20 @@ testRule(rule, {
]
});

test("One warning for each unknown at rule", done => {
expect.assertions(3);
test("One warning for each unknown at rule", () => {
return new Promise(done => {
expect.assertions(3);

postcss([rule()])
.process("@foo { } @bar { }", { from: undefined })
.then(result => {
const warnings = result.warnings();
postcss([rule()])
.process("@foo { } @bar { }", { from: undefined })
.then(result => {
const warnings = result.warnings();

expect(warnings).toHaveLength(2);
expect(warnings[0].text).toBe(messages.rejected("@foo"));
expect(warnings[1].text).toBe(messages.rejected("@bar"));
done();
})
.catch(logError);
expect(warnings).toHaveLength(2);
expect(warnings[0].text).toBe(messages.rejected("@foo"));
expect(warnings[1].text).toBe(messages.rejected("@bar"));
done();
})
.catch(logError);
});
});
4 changes: 1 addition & 3 deletions src/rules/at-rule-no-unknown/index.js
Expand Up @@ -58,9 +58,7 @@ function rule(primaryOption, secondaryOptions) {

const optionsAtRules = secondaryOptions && secondaryOptions.ignoreAtRules;
const ignoreAtRules = sassAtRules.concat(optionsAtRules || []);
const defaultedOptions = Object.assign({}, secondaryOptions, {
ignoreAtRules
});
const defaultedOptions = { ...secondaryOptions, ignoreAtRules };

utils.checkAgainstRule(
{
Expand Down
12 changes: 9 additions & 3 deletions src/rules/dollar-variable-empty-line-after/index.js
Expand Up @@ -182,7 +182,9 @@ function rule(expectation, options, context) {
}

return;
} else if (
}

if (
(expectEmptyLineAfter &&
exceptBeforeComment &&
nextIsComment &&
Expand All @@ -197,7 +199,9 @@ function rule(expectation, options, context) {
fixNext(next, context.newline + context.newline, context.newline);

return;
} else if (
}

if (
(!expectEmptyLineAfter &&
exceptBeforeComment &&
nextIsComment &&
Expand All @@ -222,7 +226,9 @@ function rule(expectation, options, context) {
fixParent(decl, context.newline, context.newline + context.newline);

return;
} else if (!expectEmptyLineAfter && hasEmptyLineAfter) {
}

if (!expectEmptyLineAfter && hasEmptyLineAfter) {
fixParent(decl, "\\n\\r\\n", "\r\n");
fixParent(decl, context.newline + context.newline, context.newline);

Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-global-function-names/index.js
Expand Up @@ -111,9 +111,9 @@ function errorMessage(name) {

if (rename) {
return `Expected ${sass_package}.${rename} instead of ${name}`;
} else {
return `Expected ${sass_package}.${name} instead of ${name}`;
}

return `Expected ${sass_package}.${name} instead of ${name}`;
}

function rule(value) {
Expand Down

0 comments on commit 8c10b0a

Please sign in to comment.