Skip to content

Commit

Permalink
Add "stylelint.reportDescriptionlessDisables" option (#442)
Browse files Browse the repository at this point in the history
* Add "stylelint.reportDescriptionlessDisables" option

* Fix Readme format
  • Loading branch information
kizu committed Feb 14, 2023
1 parent 91e7033 commit 0d5b869
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ e.g.
"stylelint.customSyntax": "${workspaceFolder}/custom-syntax.js"
```

### `stylelint.reportDescriptionlessDisables`

> Type: `boolean`
> Default: `false`
Sets the Stylelint [`reportDescriptionlessDisables`] option. If `true`, Stylelint reports `stylelint-disable` comments without a description.

### `stylelint.ignoreDisables`

> Type: `boolean`
Expand Down Expand Up @@ -325,6 +332,7 @@ Thank you to all our backers! [Become a backer](https://opencollective.com/style
[`config`]: https://stylelint.io/user-guide/usage/node-api#config
[`configfile`]: https://stylelint.io/user-guide/usage/options#configfile
[`configbasedir`]: https://stylelint.io/user-guide/usage/options#configbasedir
[`reportdescriptionlessdisables`]: https://stylelint.io/user-guide/usage/options#reportdescriptionlessdisables
[`ignoredisables`]: https://stylelint.io/user-guide/usage/options#ignoredisables
[`reportneedlessdisables`]: https://stylelint.io/user-guide/usage/options#reportneedlessdisables
[`reportinvalidscopedisables`]: https://stylelint.io/user-guide/usage/options#reportInvalidScopeDisables
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@
"default": "",
"description": "An absolute path to a custom PostCSS-compatible syntax module."
},
"stylelint.reportDescriptionlessDisables": {
"scope": "resource",
"type": "boolean",
"default": false,
"description": "Report `stylelint-disable` comments without a description."
},
"stylelint.ignoreDisables": {
"scope": "resource",
"type": "boolean",
"default": false,
"description": "Ignore `stylelint-disable` (e.g. `/* stylelint-disable block-no-empty */`) comments"
"description": "Ignore `stylelint-disable` (e.g. `/* stylelint-disable block-no-empty */`) comments."
},
"stylelint.reportNeedlessDisables": {
"scope": "resource",
Expand Down
9 changes: 9 additions & 0 deletions src/server/__tests__/__snapshots__/server.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Array [
"customSyntax": "",
"ignoreDisables": false,
"packageManager": "npm",
"reportDescriptionlessDisables": false,
"reportInvalidScopeDisables": false,
"reportNeedlessDisables": false,
"snippet": Array [
Expand Down Expand Up @@ -195,6 +196,7 @@ Array [
"customSyntax": "",
"ignoreDisables": false,
"packageManager": "npm",
"reportDescriptionlessDisables": false,
"reportInvalidScopeDisables": false,
"reportNeedlessDisables": false,
"snippet": Array [
Expand Down Expand Up @@ -232,6 +234,7 @@ Array [
"customSyntax": "",
"ignoreDisables": false,
"packageManager": "npm",
"reportDescriptionlessDisables": false,
"reportInvalidScopeDisables": false,
"reportNeedlessDisables": false,
"snippet": Array [
Expand Down Expand Up @@ -262,6 +265,7 @@ Array [
"customSyntax": "",
"ignoreDisables": false,
"packageManager": "npm",
"reportDescriptionlessDisables": false,
"reportInvalidScopeDisables": false,
"reportNeedlessDisables": false,
"snippet": Array [
Expand Down Expand Up @@ -317,6 +321,7 @@ Object {
"customSyntax": "",
"ignoreDisables": false,
"packageManager": "yarn",
"reportDescriptionlessDisables": false,
"reportInvalidScopeDisables": false,
"reportNeedlessDisables": false,
"snippet": Array [
Expand Down Expand Up @@ -344,6 +349,7 @@ Object {
"customSyntax": "",
"ignoreDisables": false,
"packageManager": "npm",
"reportDescriptionlessDisables": false,
"reportInvalidScopeDisables": false,
"reportNeedlessDisables": false,
"snippet": Array [
Expand All @@ -370,6 +376,7 @@ Object {
"customSyntax": "",
"ignoreDisables": false,
"packageManager": "npm",
"reportDescriptionlessDisables": false,
"reportInvalidScopeDisables": false,
"reportNeedlessDisables": false,
"snippet": Array [
Expand Down Expand Up @@ -397,6 +404,7 @@ Object {
"customSyntax": "",
"ignoreDisables": false,
"packageManager": "npm",
"reportDescriptionlessDisables": false,
"reportInvalidScopeDisables": false,
"reportNeedlessDisables": false,
"snippet": Array [
Expand All @@ -423,6 +431,7 @@ Object {
"customSyntax": "",
"ignoreDisables": false,
"packageManager": "npm",
"reportDescriptionlessDisables": false,
"reportInvalidScopeDisables": false,
"reportNeedlessDisables": false,
"snippet": Array [
Expand Down
1 change: 1 addition & 0 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const defaultOptions: LanguageServerOptions = {
customSyntax: '',
ignoreDisables: false,
packageManager: 'npm',
reportDescriptionlessDisables: false,
reportInvalidScopeDisables: false,
reportNeedlessDisables: false,
snippet: ['css', 'postcss'],
Expand Down
1 change: 1 addition & 0 deletions src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export type LanguageServerOptions = {
customSyntax?: string;
ignoreDisables?: boolean;
packageManager: PackageManager;
reportDescriptionlessDisables?: boolean;
reportInvalidScopeDisables?: boolean;
reportNeedlessDisables?: boolean;
snippet: string[];
Expand Down
1 change: 1 addition & 0 deletions src/utils/documents/__tests__/get-fixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('getFixes', () => {
customSyntax: 'postcss-scss',
},
fix: false,
reportDescriptionlessDisables: false,
reportNeedlessDisables: true,
reportInvalidScopeDisables: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Object {
"formatter": [Function],
"ignoreDisables": undefined,
"ignorePath": "/.stylelintignore",
"reportDescriptionlessDisables": undefined,
"reportInvalidScopeDisables": undefined,
"reportNeedlessDisables": undefined,
}
Expand Down
11 changes: 11 additions & 0 deletions src/utils/stylelint/__tests__/build-stylelint-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe('buildStylelintOptions', () => {
customSyntax: 'postcss-scss',
ignoreDisables: false,
ignorePath: '/.stylelintignore',
reportDescriptionlessDisables: false,
reportNeedlessDisables: false,
reportInvalidScopeDisables: false,
};
Expand All @@ -103,6 +104,7 @@ describe('buildStylelintOptions', () => {
customSyntax: 'postcss-scss',
ignoreDisables: true,
ignorePath: '/.stylelintignore',
reportDescriptionlessDisables: true,
reportNeedlessDisables: true,
reportInvalidScopeDisables: true,
};
Expand All @@ -113,6 +115,7 @@ describe('buildStylelintOptions', () => {
configBasedir: '/workspace',
customSyntax: 'postcss-html',
ignoreDisables: false,
reportDescriptionlessDisables: false,
reportNeedlessDisables: false,
reportInvalidScopeDisables: false,
};
Expand Down Expand Up @@ -140,6 +143,7 @@ describe('buildStylelintOptions', () => {
customSyntax: 'postcss-scss',
ignoreDisables: true,
ignorePath: '/.stylelintignore',
reportDescriptionlessDisables: true,
reportNeedlessDisables: true,
reportInvalidScopeDisables: true,
};
Expand All @@ -150,6 +154,7 @@ describe('buildStylelintOptions', () => {
configBasedir: '/workspace',
customSyntax: '${workspaceFolder}/postcss-html',
ignoreDisables: false,
reportDescriptionlessDisables: false,
reportNeedlessDisables: false,
reportInvalidScopeDisables: false,
};
Expand Down Expand Up @@ -181,6 +186,7 @@ describe('buildStylelintOptions', () => {
customSyntax: 'postcss-scss',
ignoreDisables: true,
ignorePath: '/.stylelintignore',
reportDescriptionlessDisables: true,
reportNeedlessDisables: true,
reportInvalidScopeDisables: true,
};
Expand All @@ -191,6 +197,7 @@ describe('buildStylelintOptions', () => {
configBasedir: '/workspace',
customSyntax: '${workspaceFolder}/postcss-html',
ignoreDisables: false,
reportDescriptionlessDisables: false,
reportNeedlessDisables: false,
reportInvalidScopeDisables: false,
};
Expand Down Expand Up @@ -220,6 +227,7 @@ describe('buildStylelintOptions', () => {
customSyntax: 'postcss-scss',
ignoreDisables: true,
ignorePath: '/.stylelintignore',
reportDescriptionlessDisables: true,
reportNeedlessDisables: true,
reportInvalidScopeDisables: true,
};
Expand All @@ -230,6 +238,7 @@ describe('buildStylelintOptions', () => {
configBasedir: './base',
customSyntax: '/workspace/postcss-html',
ignoreDisables: false,
reportDescriptionlessDisables: false,
reportNeedlessDisables: false,
reportInvalidScopeDisables: false,
};
Expand Down Expand Up @@ -259,6 +268,7 @@ describe('buildStylelintOptions', () => {
customSyntax: 'postcss-scss',
ignoreDisables: true,
ignorePath: '/.stylelintignore',
reportDescriptionlessDisables: true,
reportNeedlessDisables: true,
reportInvalidScopeDisables: true,
};
Expand All @@ -269,6 +279,7 @@ describe('buildStylelintOptions', () => {
configBasedir: './base',
customSyntax: '/workspace/postcss-html',
ignoreDisables: false,
reportDescriptionlessDisables: false,
reportNeedlessDisables: false,
reportInvalidScopeDisables: false,
};
Expand Down
4 changes: 4 additions & 0 deletions src/utils/stylelint/build-stylelint-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function buildStylelintOptions(
configBasedir,
customSyntax,
ignoreDisables,
reportDescriptionlessDisables,
reportNeedlessDisables,
reportInvalidScopeDisables,
}: RunnerOptions = {},
Expand Down Expand Up @@ -49,6 +50,9 @@ export async function buildStylelintOptions(

ignoreDisables: ignoreDisables ?? baseOptions.ignoreDisables,

reportDescriptionlessDisables:
reportDescriptionlessDisables ?? baseOptions.reportDescriptionlessDisables,

reportNeedlessDisables: reportNeedlessDisables ?? baseOptions.reportNeedlessDisables,

reportInvalidScopeDisables:
Expand Down
1 change: 1 addition & 0 deletions src/utils/stylelint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type RunnerOptions = {
customSyntax?: string;
ignoreDisables?: boolean;
packageManager?: PackageManager;
reportDescriptionlessDisables?: boolean;
reportInvalidScopeDisables?: boolean;
reportNeedlessDisables?: boolean;
snippet?: string[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"stylelint.reportDescriptionlessDisables" setting should report invalid-scope disables when enabled 1`] = `
Array [
Object {
"code": "--report-descriptionless-disables",
"message": "Disable for \\"indentation\\" is missing a description",
"range": Object {
"end": Object {
"character": 5,
"line": 2,
},
"start": Object {
"character": 4,
"line": 2,
},
},
"severity": 1,
"source": "Stylelint",
},
]
`;
17 changes: 17 additions & 0 deletions test/e2e/__tests__/report-descriptionless-disables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from 'path';
import { normalizeDiagnostic } from '../utils';

describe('"stylelint.reportDescriptionlessDisables" setting', () => {
it('should report invalid-scope disables when enabled', async () => {
const { document } = await openDocument(
path.resolve(workspaceDir, 'descriptionless-disables/test.css'),
);
const diagnostics = await waitForDiagnostics(document);

expect(
diagnostics
.map(normalizeDiagnostic)
.filter((diagnostic) => diagnostic?.code === '--report-descriptionless-disables'),
).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"stylelint.reportDescriptionlessDisables": true,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

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

a {
/* stylelint-disable-next-line indentation -- with a description */
color: #fff;
}
1 change: 1 addition & 0 deletions test/e2e/workspace/workspace.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{ "path": "config" },
{ "path": "custom-syntax" },
{ "path": "defaults" },
{ "path": "descriptionless-disables" },
{ "path": "ignore-disables" },
{ "path": "report-disables" },
{ "path": "stylelint-path" },
Expand Down
55 changes: 55 additions & 0 deletions test/integration/stylelint-vscode/__snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,61 @@ Object {
}
`;

exports[`StylelintRunner with reportDescriptionlessDisables should work properly if reportDescriptionlessDisables is true 1`] = `
Object {
"diagnostics": Array [
Object {
"code": "--report-descriptionless-disables",
"message": "Disable for \\"indentation\\" is missing a description",
"range": Object {
"end": Object {
"character": 5,
"line": 2,
},
"start": Object {
"character": 4,
"line": 2,
},
},
"severity": 1,
"source": "Stylelint",
},
Object {
"code": "--report-descriptionless-disables",
"message": "Disable for \\"indentation\\" is missing a description",
"range": Object {
"end": Object {
"character": 1,
"line": 5,
},
"start": Object {
"character": 0,
"line": 5,
},
},
"severity": 1,
"source": "Stylelint",
},
Object {
"code": "--report-descriptionless-disables",
"message": "Disable for \\"indentation\\" is missing a description",
"range": Object {
"end": Object {
"character": 15,
"line": 11,
},
"start": Object {
"character": 14,
"line": 11,
},
},
"severity": 1,
"source": "Stylelint",
},
],
}
`;

exports[`StylelintRunner with reportInvalidScopeDisables should work properly if reportInvalidScopeDisables is true 1`] = `
Object {
"diagnostics": Array [
Expand Down

0 comments on commit 0d5b869

Please sign in to comment.