Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/stylelint-16.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bjankord committed Mar 11, 2024
2 parents 140435f + f2ebba4 commit 56c25d2
Show file tree
Hide file tree
Showing 54 changed files with 1,299 additions and 3,734 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -117,7 +117,7 @@ This is a list of the lints turned on in this configuration, and what they do.
* [`scss/at-extend-no-missing-placeholder`](https://github.com/kristerkari/stylelint-scss/blob/master/src/rules/at-extend-no-missing-placeholder/README.md): Disallow at-extends (`@extend`) with missing placeholders.
* [`scss/at-function-pattern`](https://github.com/kristerkari/stylelint-scss/blob/master/src/rules/at-function-pattern/README.md): SCSS functions must be written in lowercase and match the regex `^[a-z]+([a-z0-9-]+[a-z0-9]+)?$`.
* [`scss/load-no-partial-leading-underscore`](https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/load-no-partial-leading-underscore/README.md): Disallow leading underscore in partial names in `@import`.
* [`scss/at-import-partial-extension-blacklist`](https://github.com/kristerkari/stylelint-scss/blob/master/src/rules/at-import-partial-extension-blacklist/README.md): Specify list of disallowed file extensions for partial names in `@import` commands.
* [`scss/at-import-partial-extension-disallowed-list`](https://github.com/kristerkari/stylelint-scss/blob/master/src/rules/at-import-partial-extension-disallowed-list/README.md): Specify list of disallowed file extensions for partial names in `@import` commands.
* `.scss`: Disallow the use of the `.scss` file extension in imports.
* [scss/`at-mixin-pattern`](https://github.com/kristerkari/stylelint-scss/blob/master/src/rules/at-mixin-pattern/README.md): SCSS mixins must be written in lowercase and match the regex `^[a-z]+([a-z0-9-]+[a-z0-9]+)?$`.
* [`scss/at-rule-no-unknown`](https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/at-rule-no-unknown/README.md): SCSS mixins must be written in lowercase and match the regex `^[a-z]+([a-z0-9-]+[a-z0-9]+)?$`.
Expand Down
5 changes: 1 addition & 4 deletions __tests__/README.md
@@ -1,11 +1,8 @@
# How to add tests

* Create your test file named after the scss lint your you are adding a stylelint rule for. For example, `__tests___/unit/bang-format.spec.js`
* Create your test file named after the scss lint your you are adding a stylelint rule for. For example, `__tests___/unit/bang-format.test.mjs`
* Copy the code from one of the other tests into your test new file
* Update the test so you have .scss code that will produce lint you want to test for
* Add a console.log statement within the checkResult function in the test file passing `result` to the log statement. e.g. `console.log(result)`
* Look for warnings it generates
* Copy expected text to test file
* Escape quotes in your expected error text
* Run tests again and refine until they pass
* Update `t.plan(2)` to the number of tests you have
49 changes: 49 additions & 0 deletions __tests__/border-none.test.mjs
@@ -0,0 +1,49 @@
import { beforeEach, describe, it } from 'node:test';
import assert from 'node:assert/strict';

import stylelint from 'stylelint';

import config from '../index.js';

describe('flags warnings with border none', () => {
const invalidScss = (
`.borderzero {
border: none;
}
`);

let result;

beforeEach(async () => {
result = await stylelint.lint({
code: invalidScss,
config,
});
});

it('did error', () => {
assert.equal(result.errored, true);
});

it('flags warnings', () => {
assert.equal(result.results[0].warnings.length, 1);
});

it('correct warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[
'Unexpected value "none" for property "border" (declaration-property-value-disallowed-list)',
],
);
});

it('correct rule flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[
'declaration-property-value-disallowed-list',
],
);
});
});
49 changes: 49 additions & 0 deletions __tests__/color-keyword.test.mjs
@@ -0,0 +1,49 @@
import { beforeEach, describe, it } from 'node:test';
import assert from 'node:assert/strict';

import stylelint from 'stylelint';

import config from '../index.js';

describe('flags warnings with named color keyword', () => {
const invalidScss = (
`.colorkeyword {
color: green;
}
`);

let result;

beforeEach(async () => {
result = await stylelint.lint({
code: invalidScss,
config,
});
});

it('did error', () => {
assert.equal(result.errored, true);
});

it('flags warnings', () => {
assert.equal(result.results[0].warnings.length, 1);
});

it('correct warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[
'Unexpected named color "green" (color-named)',
],
);
});

it('correct rule flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[
'color-named',
],
);
});
});
51 changes: 51 additions & 0 deletions __tests__/debug-statement.test.mjs
@@ -0,0 +1,51 @@
import { beforeEach, describe, it } from 'node:test';
import assert from 'node:assert/strict';

import stylelint from 'stylelint';

import config from '../index.js';

describe('flags warnings with debug statement scss', () => {
const invalidScss = (
`$color-blue: #1c94c6;
.debug {
@debug $color-blue;
}
`);

let result;

beforeEach(async () => {
result = await stylelint.lint({
code: invalidScss,
config,
});
});

it('did error', () => {
assert.equal(result.errored, true);
});

it('flags warnings', () => {
assert.equal(result.results[0].warnings.length, 1);
});

it('correct warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[
'Unexpected at-rule "debug" (at-rule-disallowed-list)',
],
);
});

it('correct rule flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[
'at-rule-disallowed-list',
],
);
});
});
57 changes: 57 additions & 0 deletions __tests__/empty-line-between-blocks.test.mjs
@@ -0,0 +1,57 @@
import { beforeEach, describe, it } from 'node:test';
import assert from 'node:assert/strict';

import stylelint from 'stylelint';

import config from '../index.js';

describe('flags warnings with missing empty line between blocks', () => {
const invalidScss = (
`p {
margin: 0;
em {
color: #f00;
}
}
a {
color: #f00;
}
`);

let result;

beforeEach(async () => {
result = await stylelint.lint({
code: invalidScss,
config,
});
});

it('did error', () => {
assert.equal(result.errored, true);
});

it('flags warnings', () => {
assert.equal(result.results[0].warnings.length, 2);
});

it('correct warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[
'Expected empty line before rule (rule-empty-line-before)',
'Expected empty line before rule (rule-empty-line-before)',
],
);
});

it('correct rule flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[
'rule-empty-line-before',
'rule-empty-line-before',
],
);
});
});
48 changes: 48 additions & 0 deletions __tests__/empty-rule.test.mjs
@@ -0,0 +1,48 @@
import { beforeEach, describe, it } from 'node:test';
import assert from 'node:assert/strict';

import stylelint from 'stylelint';

import config from '../index.js';

describe('flags warnings with empty rule', () => {
const invalidScss = (
`.cat {
}
`);

let result;

beforeEach(async () => {
result = await stylelint.lint({
code: invalidScss,
config,
});
});

it('did error', () => {
assert.equal(result.errored, true);
});

it('flags warnings', () => {
assert.equal(result.results[0].warnings.length, 1);
});

it('correct warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[
'Unexpected empty block (block-no-empty)',
],
);
});

it('correct rule flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[
'block-no-empty',
],
);
});
});
49 changes: 49 additions & 0 deletions __tests__/hex-length.test.mjs
@@ -0,0 +1,49 @@
import { beforeEach, describe, it } from 'node:test';
import assert from 'node:assert/strict';

import stylelint from 'stylelint';

import config from '../index.js';

describe('flags warnings with hex color length', () => {
const invalidScss = (
`.hexlength {
color: #ff22ee;
}
`);

let result;

beforeEach(async () => {
result = await stylelint.lint({
code: invalidScss,
config,
});
});

it('did error', () => {
assert.equal(result.errored, true);
});

it('flags warnings', () => {
assert.equal(result.results[0].warnings.length, 1);
});

it('correct warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[
'Expected "#ff22ee" to be "#f2e" (color-hex-length)',
],
);
});

it('correct rule flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[
'color-hex-length',
],
);
});
});
49 changes: 49 additions & 0 deletions __tests__/hex-validation.test.mjs
@@ -0,0 +1,49 @@
import { beforeEach, describe, it } from 'node:test';
import assert from 'node:assert/strict';

import stylelint from 'stylelint';

import config from '../index.js';

describe('flags warnings with hex validation', () => {
const invalidScss = (
`.hex-validation {
background: #ab; // Clearly a typo
}
`);

let result;

beforeEach(async () => {
result = await stylelint.lint({
code: invalidScss,
config,
});
});

it('did error', () => {
assert.equal(result.errored, true);
});

it('flags warnings', () => {
assert.equal(result.results[0].warnings.length, 1);
});

it('correct warning text', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.text),
[
'Unexpected invalid hex color "#ab" (color-no-invalid-hex)',
],
);
});

it('correct rule flagged', () => {
assert.deepEqual(
result.results[0].warnings.map((w) => w.rule),
[
'color-no-invalid-hex',
],
);
});
});

0 comments on commit 56c25d2

Please sign in to comment.