Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: stylelint/stylelint
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 14.14.1
Choose a base ref
...
head repository: stylelint/stylelint
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 14.15.0
Choose a head ref
  • 14 commits
  • 36 files changed
  • 8 contributors

Commits on Nov 4, 2022

  1. Copy the full SHA
    1a63e71 View commit details
  2. [Fix] Support import-lazy bundler format (#6449)

    Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
    phoenisx and ybiquitous authored Nov 4, 2022
    Copy the full SHA
    2724aa4 View commit details

Commits on Nov 8, 2022

  1. Bump eslint from 8.26.0 to 8.27.0 (#6457)

    Bumps [eslint](https://github.com/eslint/eslint) from 8.26.0 to 8.27.0.
    - [Release notes](https://github.com/eslint/eslint/releases)
    - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
    - [Commits](eslint/eslint@v8.26.0...v8.27.0)
    
    ---
    updated-dependencies:
    - dependency-name: eslint
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    ybiquitous and dependabot[bot] authored Nov 8, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    17cff27 View commit details

Commits on Nov 9, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    35c0cfa View commit details

Commits on Nov 10, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    64b022a View commit details

Commits on Nov 11, 2022

  1. Copy the full SHA
    e65d244 View commit details
  2. Add support to checkAgainstRule with custom rules (#6460)

    Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
    aaronccasanova and ybiquitous authored Nov 11, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d91bb5b View commit details
  3. Add --globby-options flag (#6437)

    Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
    sidverma32 and ybiquitous authored Nov 11, 2022
    Copy the full SHA
    b54083c View commit details
  4. Add support autofix with checkAgainstRule (#6466)

    Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
    aaronccasanova and ybiquitous authored Nov 11, 2022
    Copy the full SHA
    11b3c1e View commit details
  5. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    971a58c View commit details
  6. Copy the full SHA
    4ec0c74 View commit details

Commits on Nov 13, 2022

  1. Update deps (#6474)

    ybiquitous authored Nov 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3c404f6 View commit details
  2. Prepare release (#6451)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Nov 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b576717 View commit details
  3. 14.15.0

    ybiquitous committed Nov 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d1705d0 View commit details
Showing with 831 additions and 407 deletions.
  1. +1 −0 .github/dependabot.yml
  2. +2 −2 .github/workflows/testing.yml
  3. +10 −0 CHANGELOG.md
  4. +7 −3 docs/developer-guide/plugins.md
  5. +4 −0 docs/user-guide/usage/cli.md
  6. +6 −0 docs/user-guide/usage/options.md
  7. +4 −0 lib/__tests__/__snapshots__/cli.test.js.snap
  8. +28 −0 lib/__tests__/cli.test.js
  9. +1 −0 lib/__tests__/fixtures/globby-options/.dot/empty-block.css
  10. +29 −21 lib/__tests__/normalizeRuleSettings.test.js
  11. +50 −0 lib/cli.js
  12. +8 −10 lib/formatters/index.js
  13. +3 −4 lib/formatters/stringFormatter.js
  14. +2 −2 lib/lintPostcssResult.js
  15. +3 −7 lib/normalizeAllRuleSettings.js
  16. +8 −22 lib/normalizeRuleSettings.js
  17. +2 −0 lib/rules/at-rule-disallowed-list/README.md
  18. +2 −1 lib/rules/at-rule-disallowed-list/index.js
  19. +2 −0 lib/rules/declaration-property-unit-disallowed-list/README.md
  20. +2 −1 lib/rules/declaration-property-unit-disallowed-list/index.js
  21. +2 −0 lib/rules/declaration-property-value-disallowed-list/README.md
  22. +2 −1 lib/rules/declaration-property-value-disallowed-list/index.js
  23. +2 −0 lib/rules/function-disallowed-list/README.md
  24. +2 −1 lib/rules/function-disallowed-list/index.js
  25. +357 −249 lib/rules/index.js
  26. +2 −0 lib/rules/property-disallowed-list/README.md
  27. +2 −1 lib/rules/property-disallowed-list/index.js
  28. +102 −0 lib/utils/__tests__/checkAgainstRule.test.js
  29. +72 −0 lib/utils/__tests__/report.test.js
  30. +16 −25 lib/utils/checkAgainstRule.js
  31. +10 −0 lib/utils/getStylelintRule.js
  32. +9 −7 lib/utils/report.js
  33. +37 −37 package-lock.json
  34. +6 −6 package.json
  35. +14 −0 patches/import-lazy+4.0.0.patch
  36. +22 −7 types/stylelint/index.d.ts
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ updates:
labels:
- 'pr: dependencies'
versioning-strategy: increase
target-branch: v15 # TODO: We should remove this line after shipping v15.

- package-ecosystem: github-actions
directory: '/'
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ on:
push:
branches:
- main
- 'dependabot/**'
pull_request:
branches:
- '**'
@@ -39,7 +38,8 @@ jobs:
cache: npm

- name: Install latest npm
run: npm install --global npm@latest
# TODO: npm@9 is the latest, but it doesn't work on Node.js v12 and v14 with windows.
run: npm install --global npm@8

- name: Install dependencies
run: npm ci
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 14.15.0

- Added: `--globby-options` flag ([#6437](https://github.com/stylelint/stylelint/pull/6437)) ([@sidverma32](https://github.com/sidverma32)).
- Added: custom message formatting for `at-rule-disallowed-list`, `declaration-property-unit-disallowed-list`, `declaration-property-value-disallowed-list`, `function-disallowed-list`, and `property-disallowed-list` ([#6463](https://github.com/stylelint/stylelint/pull/6463)) ([@chloerice](https://github.com/chloerice)).
- Added: support autofix with `checkAgainstRule` ([#6466](https://github.com/stylelint/stylelint/pull/6466)) ([@aaronccasanova](https://github.com/aaronccasanova)).
- Added: support for reporting with custom severity ([#6444](https://github.com/stylelint/stylelint/pull/6444)) ([@aaronccasanova](https://github.com/aaronccasanova)).
- Added: support to `checkAgainstRule` with custom rules ([#6460](https://github.com/stylelint/stylelint/pull/6460)) ([@aaronccasanova](https://github.com/aaronccasanova)).
- Fixed: tally output of `string` formatter colorized ([#6443](https://github.com/stylelint/stylelint/pull/6443)) ([@ybiquitous](https://github.com/ybiquitous)).
- Fixed: usage of the `import-lazy` package to fit bundlers ([#6449](https://github.com/stylelint/stylelint/pull/6449)) ([@phoenisx](https://github.com/phoenisx)).

## 14.14.1

- Fixed: `declaration-block-no-redundant-longhand-properties` false positives for `inherit` keyword ([#6419](https://github.com/stylelint/stylelint/pull/6419)) ([@kimulaco](https://github.com/kimulaco)).
10 changes: 7 additions & 3 deletions docs/developer-guide/plugins.md
Original file line number Diff line number Diff line change
@@ -232,13 +232,15 @@ Validates the options for your rule.

### `stylelint.utils.checkAgainstRule`

Checks CSS against a standard Stylelint rule _within your own rule_. This function provides power and flexibility for plugins authors who wish to modify, constrain, or extend the functionality of existing Stylelint rules.
Checks CSS against a standard or custom Stylelint rule _within your own rule_. This function provides power and flexibility for plugins authors who wish to modify, constrain, or extend the functionality of existing Stylelint rules.

It accepts an options object and a callback that is invoked with warnings from the specified rule. The options are:

- `ruleName`: the name of the rule you are invoking
- `ruleSettings`: settings for the rule you are invoking
- `root`: the root node to run this rule against
- `result?`: the PostCSS result for resolving and invoking custom rules
- `context?`: the [context](rules.md#add-autofix) for the rule you are invoking

Use the warning to create a _new_ warning _from your plugin rule_ that you report with `stylelint.utils.report`.

@@ -249,7 +251,7 @@ const allowableAtRules = [
/* .. */
];

function myPluginRule(primaryOption, secondaryOptionObject) {
function myPluginRule(primaryOption, secondaryOptionObject, ruleContext) {
return (postcssRoot, postcssResult) => {
const defaultedOptions = Object.assign({}, secondaryOptionObject, {
ignoreAtRules: allowableAtRules.concat(options.ignoreAtRules || [])
@@ -259,7 +261,9 @@ function myPluginRule(primaryOption, secondaryOptionObject) {
{
ruleName: "at-rule-no-unknown",
ruleSettings: [primaryOption, defaultedOptions],
root: postcssRoot
root: postcssRoot,
result: postcssResult,
context: ruleContext
},
(warning) => {
stylelint.utils.report({
4 changes: 4 additions & 0 deletions docs/user-guide/usage/cli.md
Original file line number Diff line number Diff line change
@@ -68,6 +68,10 @@ Automatically fix, where possible, problems reported by rules. [More info](optio

Specify the formatter to format your results. [More info](options.md#formatter).

## `--globbyOptions, --go`

Options in JSON format passed to [globby](https://github.com/sindresorhus/globby). [More info](options.md#globbyoptions).

### `--ignore-disables, --id`

Ignore `stylelint-disable` (e.g. `/* stylelint-disable block-no-empty */`) comments. [More info](options.md#ignoredisables).
6 changes: 6 additions & 0 deletions docs/user-guide/usage/options.md
Original file line number Diff line number Diff line change
@@ -139,6 +139,12 @@ CLI flags: `--disable-default-ignores, --di`

Disable the default ignores. Stylelint will not automatically ignore the contents of `node_modules`.

## `globbyOptions`

CLI flags: `--globby-options, --go`

Options passed to [globby](https://github.com/sindresorhus/globby). [More info](node-api.md#globbyoptions).

## `ignorePath`

CLI flags: `--ignore-path, -i`
4 changes: 4 additions & 0 deletions lib/__tests__/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
@@ -149,5 +149,9 @@ exports[`CLI --help 1`] = `
--allow-empty-input, --aei
When glob pattern matches no files, the process will exit without throwing an error.
--globby-options, --go
Options in JSON format passed to globby.
"
`;
28 changes: 28 additions & 0 deletions lib/__tests__/cli.test.js
Original file line number Diff line number Diff line change
@@ -50,6 +50,11 @@ describe('buildCLI', () => {
expect(buildCLI(['--cache-location=foo']).flags.cacheLocation).toBe('foo');
});

it('flags.globbyOptions', () => {
expect(buildCLI(['--globby-options={"dot":true}']).flags.globbyOptions).toBe('{"dot":true}');
expect(buildCLI(['--go={"dot":true}']).flags.globbyOptions).toBe('{"dot":true}');
});

it('flags.cacheStrategy', () => {
expect(buildCLI(['--cache-strategy=content']).flags.cacheStrategy).toBe('content');
expect(buildCLI(['--cache-strategy=metadata']).flags.cacheStrategy).toBe('metadata');
@@ -374,4 +379,27 @@ describe('CLI', () => {

expect(output).toBe('Custom formatter reports 1 warning(s).');
});

it('output a message when wrong --globby-options provided', async () => {
await cli(['--globby-options=wrong']);

expect(process.exitCode).toBe(2);
expect(process.stdout.write).toHaveBeenCalledTimes(0);
expect(process.stderr.write).toHaveBeenCalledTimes(1);
expect(stripAnsi(process.stderr.write.mock.calls[0][0])).toContain(
'Invalid option "--globby-options". The value "wrong" is not valid JSON object.',
);
});

it('--globby-options', async () => {
await cli([
'--globby-options={"dot":true}',
'--config',
fixturesPath('config-block-no-empty.json'),
fixturesPath('globby-options'),
]);

expect(process.stdout.write).toHaveBeenCalledTimes(1);
expect(process.stdout.write).toHaveBeenCalledWith(expect.stringMatching(/block-no-empty/));
});
});
1 change: 1 addition & 0 deletions lib/__tests__/fixtures/globby-options/.dot/empty-block.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a {}
50 changes: 29 additions & 21 deletions lib/__tests__/normalizeRuleSettings.test.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,84 @@
'use strict';

const rules = require('../rules');
const createPlugin = require('../createPlugin');
const normalizeRuleSettings = require('../normalizeRuleSettings');

const mockRule = createPlugin('mock-rule', () => () => {});
const mockRuleWithPrimaryOptionArray = createPlugin(
'mock-rule-with-primary-option-array',
() => () => {},
);

mockRuleWithPrimaryOptionArray.primaryOptionArray = true;

describe('rules whose primary option IS NOT an array', () => {
it('solo null returns null', () => {
expect(normalizeRuleSettings(null, 'foo')).toBeNull();
expect(normalizeRuleSettings(null, mockRule)).toBeNull();
});

it('arrayed null returns null', () => {
expect(normalizeRuleSettings([null], 'foo')).toBeNull();
expect(normalizeRuleSettings([null], mockRule)).toBeNull();
});

it('solo number returns arrayed number', () => {
const actual = normalizeRuleSettings(2, 'foo');
const actual = normalizeRuleSettings(2, mockRule);
const expected = [2];

expect(actual).toEqual(expected);
});

it('arrayed number returns arrayed number if rule is not special', () => {
const actual = normalizeRuleSettings([2], 'foo');
const actual = normalizeRuleSettings([2], mockRule);
const expected = [2];

expect(actual).toEqual(expected);
});

it('arrayed number with secondary options returns same', () => {
const actual = normalizeRuleSettings([2, { severity: 'warning' }], 'block-no-empty');
const actual = normalizeRuleSettings([2, { severity: 'warning' }], rules['block-no-empty']);
const expected = [2, { severity: 'warning' }];

expect(actual).toEqual(expected);
});

it('solo string returns arrayed string', () => {
const actual = normalizeRuleSettings('always', 'foo');
const actual = normalizeRuleSettings('always', mockRule);
const expected = ['always'];

expect(actual).toEqual(expected);
});

it('arrayed string returns arrayed string', () => {
const actual = normalizeRuleSettings(['always'], 'foo');
const actual = normalizeRuleSettings(['always'], mockRule);
const expected = ['always'];

expect(actual).toEqual(expected);
});

it('arrayed string with secondary options returns same', () => {
const actual = normalizeRuleSettings(['always', { severity: 'warning' }], 'foo');
const actual = normalizeRuleSettings(['always', { severity: 'warning' }], mockRule);
const expected = ['always', { severity: 'warning' }];

expect(actual).toEqual(expected);
});

it('solo boolean returns arrayed boolean', () => {
const actual = normalizeRuleSettings(true, 'foo');
const actual = normalizeRuleSettings(true, mockRule);
const expected = [true];

expect(actual).toEqual(expected);
});

it('arrayed boolean returns arrayed boolean if rule is not special', () => {
const actual = normalizeRuleSettings([false], 'foo');
const actual = normalizeRuleSettings([false], mockRule);
const expected = [false];

expect(actual).toEqual(expected);
});

it('arrayed boolean with secondary options returns same', () => {
const actual = normalizeRuleSettings([true, { severity: 'warning' }], 'block-no-empty');
const actual = normalizeRuleSettings([true, { severity: 'warning' }], rules['block-no-empty']);
const expected = [true, { severity: 'warning' }];

expect(actual).toEqual(expected);
@@ -77,22 +87,22 @@ describe('rules whose primary option IS NOT an array', () => {

describe('rules whose primary option CAN BE an array', () => {
it('solo null returns null', () => {
expect(normalizeRuleSettings(null, 'foo')).toBeNull();
expect(normalizeRuleSettings(null, mockRule)).toBeNull();
});

it('arrayed null returns null', () => {
expect(normalizeRuleSettings([null], 'foo')).toBeNull();
expect(normalizeRuleSettings([null], mockRule)).toBeNull();
});

it('solo primary option array is nested within an array', () => {
const actual = normalizeRuleSettings(['calc', 'rgba'], 'function-allowed-list', true);
const actual = normalizeRuleSettings(['calc', 'rgba'], rules['function-allowed-list']);
const expected = [['calc', 'rgba']];

expect(actual).toEqual(expected);
});

it('primary option array in an array', () => {
const actual = normalizeRuleSettings([['calc', 'rgba']], 'function-allowed-list', true);
const actual = normalizeRuleSettings([['calc', 'rgba']], rules['function-allowed-list']);
const expected = [['calc', 'rgba']];

expect(actual).toEqual(expected);
@@ -101,23 +111,22 @@ describe('rules whose primary option CAN BE an array', () => {
it('nested primary option array returns same', () => {
const actual = normalizeRuleSettings(
[['calc', 'rgba'], { severity: 'warning' }],
'function-allowed-list',
true,
rules['function-allowed-list'],
);
const expected = [['calc', 'rgba'], { severity: 'warning' }];

expect(actual).toEqual(expected);
});

it('string as first primary option returns same', () => {
const actual = normalizeRuleSettings(['alphabetical', { severity: 'warning' }], 'rulename-bar');
const actual = normalizeRuleSettings(['alphabetical', { severity: 'warning' }], mockRule);
const expected = ['alphabetical', { severity: 'warning' }];

expect(actual).toEqual(expected);
});

it('primary option array with length of 2', () => {
const actual = normalizeRuleSettings([{ foo: 1 }, { foo: 2 }], 'rulename-bar', true);
const actual = normalizeRuleSettings([{ foo: 1 }, { foo: 2 }], mockRuleWithPrimaryOptionArray);
const expected = [[{ foo: 1 }, { foo: 2 }]];

expect(actual).toEqual(expected);
@@ -126,8 +135,7 @@ describe('rules whose primary option CAN BE an array', () => {
it('primary option array with length of 2 and secondary options', () => {
const actual = normalizeRuleSettings(
[[{ foo: 1 }, { foo: 2 }], { severity: 'warning' }],
'rulename-bar',
true,
mockRuleWithPrimaryOptionArray,
);
const expected = [[{ foo: 1 }, { foo: 2 }], { severity: 'warning' }];

Loading