Skip to content

Commit

Permalink
Merge pull request #118 from stylelint/ignore-disables
Browse files Browse the repository at this point in the history
Add "stylelint.ignoreDisables" option
  • Loading branch information
ntwb committed Jun 8, 2020
2 parents 9a0c69d + ad9cc6b commit ec802e8
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ e.g.
"stylelint.customSyntax": "${workspaceFolder}/custom-syntax.js"
```

#### stylelint.ignoreDisables

Type: `boolean`
Default: `false`

Set stylelint [`ignoreDisables`](https://stylelint.io/user-guide/usage/options#ignoredisables) option. If `true`, ignore `styleline-disable` (e.g. `/* stylelint-disable block-no-empty */`) comments.

#### stylelint.reportNeedlessDisables

Type: `boolean`
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
"default": "",
"description": "An absolute path to a custom PostCSS-compatible syntax module."
},
"stylelint.ignoreDisables": {
"type": "boolean",
"default": false,
"description": "Ignore `styleline-disable` (e.g. `/* stylelint-disable block-no-empty */`) comments"
},
"stylelint.reportNeedlessDisables": {
"type": "boolean",
"default": false,
Expand Down
7 changes: 7 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ let packageManager;
/** @type {string} */
let customSyntax;
/** @type {boolean} */
let ignoreDisables;
/** @type {boolean} */
let reportNeedlessDisables;
/** @type {boolean} */
let reportInvalidScopeDisables;
Expand Down Expand Up @@ -101,6 +103,10 @@ async function buildStylelintOptions(document, baseOptions = {}) {
options.configOverrides = configOverrides;
}

if (ignoreDisables) {
options.ignoreDisables = ignoreDisables;
}

if (reportNeedlessDisables) {
options.reportNeedlessDisables = reportNeedlessDisables;
}
Expand Down Expand Up @@ -312,6 +318,7 @@ connection.onDidChangeConfiguration(({ settings }) => {
configOverrides = settings.stylelint.configOverrides;
configBasedir = settings.stylelint.configBasedir;
customSyntax = settings.stylelint.customSyntax;
ignoreDisables = settings.stylelint.ignoreDisables;
reportNeedlessDisables = settings.stylelint.reportNeedlessDisables;
reportInvalidScopeDisables = settings.stylelint.reportInvalidScopeDisables;
stylelintPath = settings.stylelint.stylelintPath;
Expand Down
3 changes: 3 additions & 0 deletions test/ws-ignore-disables-test/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"stylelint.ignoreDisables": true
}
68 changes: 68 additions & 0 deletions test/ws-ignore-disables-test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const path = require('path');
const pWaitFor = require('p-wait-for');
const test = require('tape');
const { extensions, workspace, window, Uri, commands, languages } = require('vscode');
const { normalizeDiagnostic } = require('../utils');

const run = () =>
test('vscode-stylelint with "stylelint.ignoreDisables"', async (t) => {
await commands.executeCommand('vscode.openFolder', Uri.file(__dirname));

const vscodeStylelint = extensions.getExtension('stylelint.vscode-stylelint');

// Open the './test.css' file.
const cssDocument = await workspace.openTextDocument(path.resolve(__dirname, 'test.css'));

await window.showTextDocument(cssDocument);

// Wait for diagnostics result.
await pWaitFor(() => vscodeStylelint.isActive, { timeout: 2000 });
await pWaitFor(() => languages.getDiagnostics(cssDocument.uri).length > 0, { timeout: 5000 });

// Check the result.
const diagnostics = languages.getDiagnostics(cssDocument.uri);

t.deepEqual(
diagnostics.map(normalizeDiagnostic),
[
{
range: { start: { line: 3, character: 9 }, end: { line: 3, character: 9 } },
message: 'Expected "#fff" to be "#FFF" (color-hex-case)',
severity: 0,
code: {
value: 'color-hex-case',
target: {
scheme: 'https',
authority: 'stylelint.io',
path: '/user-guide/rules/color-hex-case',
},
},
source: 'stylelint',
},
{
range: { start: { line: 3, character: 2 }, end: { line: 3, character: 2 } },
message: 'Expected indentation of 4 spaces (indentation)',
severity: 0,
code: {
value: 'indentation',
target: {
scheme: 'https',
authority: 'stylelint.io',
path: '/user-guide/rules/indentation',
},
},
source: 'stylelint',
},
],
'should work if "stylelint.ignoreDisables" is enabled.',
);

t.end();
});

exports.run = (root, done) => {
test.onFinish(done);
run();
};
8 changes: 8 additions & 0 deletions test/ws-ignore-disables-test/stylelint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
rules: {
indentation: [4],
'color-hex-case': ['upper'],
},
};
5 changes: 5 additions & 0 deletions test/ws-ignore-disables-test/test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* prettier-ignore */
a {
/* stylelint-disable-next-line indentation */
color: #fff;
}

0 comments on commit ec802e8

Please sign in to comment.