Skip to content

Commit

Permalink
Merge branch 'main' into v15
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Dec 3, 2022
2 parents 7f49d07 + 11acf31 commit 046c576
Show file tree
Hide file tree
Showing 16 changed files with 620 additions and 182 deletions.
29 changes: 21 additions & 8 deletions .changeset/changelog-stylelint.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ const changelogFunctions = {
return Object.entries(resolved)
.reduce((acc, [_type, lines]) => {
const type = /** @type {ReleaseType} */ (_type);

lines.forEach((line) => {
if (line) {
acc.push(`${line}${type === 'major' ? ' (BREAKING)' : ''}`);
}
});

return acc;
}, /** @type {string[]} */ ([]))
.sort((a, b) => {
const aSection = changesetSectionReg.exec(a)?.[1];
const bSection = changesetSectionReg.exec(b)?.[1];

return aSection === bSection
? a.localeCompare(b)
: CHANGESET_SECTIONS.indexOf(aSection) - CHANGESET_SECTIONS.indexOf(bSection);
Expand Down Expand Up @@ -66,15 +69,19 @@ const changelogFunctions = {
const replacedChangelog = changeset.summary
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
let num = Number(pr);

if (!isNaN(num)) prFromSummary = num;

return '';
})
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
.replace(/^\s*commit:\s*(\S+)/im, (_, commit) => {
commitFromSummary = commit;

return '';
})
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
.replace(/^\s*(?:author|user):\s*@?(\S+)/gim, (_, user) => {
usersFromSummary.push(user);

return '';
})
.trim();
Expand All @@ -83,26 +90,32 @@ const changelogFunctions = {

const links = await (async () => {
if (prFromSummary !== undefined) {
let { links } = await getInfoFromPullRequest({
let { links: resultLinks } = await getInfoFromPullRequest({
repo: options.repo,
pull: prFromSummary,
});

if (commitFromSummary) {
links = {
...links,
resultLinks = {
...resultLinks,
commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
};
}
return links;

return resultLinks;
}

const commitToFetchFrom = commitFromSummary || changeset.commit;

if (commitToFetchFrom) {
let { links } = await getInfo({
let { links: resultLinks } = await getInfo({
repo: options.repo,
commit: commitToFetchFrom,
});
return links;

return resultLinks;
}

return {
commit: null,
pull: null,
Expand Down
5 changes: 0 additions & 5 deletions .changeset/nice-carpets-yawn.md

This file was deleted.

3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ lib/vendor

# Unignore config files like .prettierrc.js, because they're ignored by default
!.*rc.js

# Unignore dot-folders
!/.changeset
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 14.16.0

- Added: `media-feature-range-notation` rule ([#6497](https://github.com/stylelint/stylelint/pull/6497)) ([@jeddy3](https://github.com/jeddy3)).
- Added: support for plugin objects as config values ([#6481](https://github.com/stylelint/stylelint/pull/6481)) ([@phoenisx](https://github.com/phoenisx)).
- Fixed: incorrect output by all formatters except for `json` ([#6480](https://github.com/stylelint/stylelint/pull/6480)) ([@ybiquitous](https://github.com/ybiquitous)).

## 14.15.0

- Added: `--globby-options` flag ([#6437](https://github.com/stylelint/stylelint/pull/6437)) ([@sidverma32](https://github.com/sidverma32)).
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ For example, [stylelint-scss](https://github.com/stylelint-scss/stylelint-scss)

You'll find more in [awesome stylelint](https://github.com/stylelint/awesome-stylelint#plugins).

To use one, add a `"plugins"` array to your config, containing "locaters" identifying the plugins you want to use. As with `extends`, above, a "locater" can be either a:
To use one, add a `"plugins"` array to your config, containing either [plugin objects](../developer-guide/plugins.md) or "locaters" identifying the plugins you want to use. As with `extends`, above, a "locater" can be either a:

- npm module name
- absolute path
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Enforce one representation of things that have multiple with these `notation` (s
- [`hue-degree-notation`](../../lib/rules/hue-degree-notation/README.md): Specify number or angle notation for degree hues (Autofixable).
- [`import-notation`](../../lib/rules/import-notation/README.md): Specify string or URL notation for `@import` rules (Autofixable).
- [`keyframe-selector-notation`](../../lib/rules/keyframe-selector-notation/README.md): Specify keyword or percentage notation for keyframe selectors (Autofixable).
- [`media-feature-range-notation`](../../lib/rules/media-feature-range-notation/README.md): Specify context or prefix notation for media feature ranges.
- [`selector-not-notation`](../../lib/rules/selector-not-notation/README.md): Specify simple or complex notation for `:not()` pseudo-class selectors (Autofixable).
- [`selector-pseudo-element-colon-notation`](../../lib/rules/selector-pseudo-element-colon-notation/README.md): Specify single or double colon notation for applicable pseudo-element selectors (Autofixable).

Expand Down
42 changes: 42 additions & 0 deletions lib/__tests__/plugins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ const configRelativeAndExtendRelative = {
},
};

const configPluginRequire = {
plugins: [require('./fixtures/plugin-warn-about-foo')],
rules: {
'plugin/warn-about-foo': 'always',
'block-no-empty': true,
},
};

const processorRelative = postcss().use(
stylelint({ config: configRelative, configBasedir: __dirname }),
);
Expand All @@ -52,6 +60,7 @@ const processorRelativeAndExtendRelative = postcss().use(
configBasedir: __dirname,
}),
);
const processorPluginRequire = postcss().use(stylelint({ config: configPluginRequire }));

it('one plugin runs', async () => {
const result = await processorRelative.process(cssWithFoo, { from: undefined });
Expand Down Expand Up @@ -108,6 +117,39 @@ it('config with its own plugins extending another config that invokes a plugin w
expect(result.warnings()[0].node).toBeTruthy();
});

it('plugin with CJS require()', async () => {
const result = await processorPluginRequire.process(cssWithFoo, { from: undefined });

expect(result.warnings()).toHaveLength(2);
expect(result.warnings()[0].text).toBe('found .foo (plugin/warn-about-foo)');
expect(result.warnings()[1].text).toBe('Unexpected empty block (block-no-empty)');
expect(result.warnings()[0].node).toBeTruthy();
});

it('plugin with ESM import()', async () => {
const result = await postcss()
.use(
stylelint({
config: {
// Following object mocks `await import()` style imports, since
// jest without node --experimental-vm-modules enabled fails to
// support dynamic ESM imports.
plugins: [{ default: require('./fixtures/plugin-warn-about-foo') }], // Similar to `await import()`
rules: {
'plugin/warn-about-foo': 'always',
'block-no-empty': true,
},
},
}),
)
.process(cssWithFoo, { from: undefined });

expect(result.warnings()).toHaveLength(2);
expect(result.warnings()[0].text).toBe('found .foo (plugin/warn-about-foo)');
expect(result.warnings()[1].text).toBe('Unexpected empty block (block-no-empty)');
expect(result.warnings()[0].node).toBeTruthy();
});

describe('plugin using exposed rules via stylelint.rules', () => {
const cssWithDirectiveLower = '/** @@check-color-hex-case */ a { color: #eee; }';
const cssWithDirectiveUpper = '/** @@check-color-hex-case */ a { color: #EEE; }';
Expand Down
16 changes: 14 additions & 2 deletions lib/augmentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ function absolutizePaths(config, configDir, cwd) {
}

if (config.plugins) {
config.plugins = [config.plugins].flat().map((lookup) => getModulePath(configDir, lookup, cwd));
config.plugins = [config.plugins].flat().map((lookup) => {
if (typeof lookup === 'string') {
return getModulePath(configDir, lookup, cwd);
}

return lookup;
});
}

return config;
Expand Down Expand Up @@ -292,7 +298,13 @@ function addPluginFunctions(config) {
const pluginFunctions = {};

for (const pluginLookup of normalizedPlugins) {
let pluginImport = require(pluginLookup);
let pluginImport;

if (typeof pluginLookup === 'string') {
pluginImport = require(pluginLookup);
} else {
pluginImport = pluginLookup;
}

// Handle either ES6 or CommonJS modules
pluginImport = pluginImport.default || pluginImport;
Expand Down
20 changes: 12 additions & 8 deletions lib/reference/mediaFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ const deprecatedMediaFeatureNames = new Set([
'min-device-width',
]);

const mediaFeatureNames = uniteSets(deprecatedMediaFeatureNames, [
'any-hover',
'any-pointer',
const rangeTypeMediaFeatureNames = new Set([
'aspect-ratio',
'color-index',
'color',
'height',
'monochrome',
'resolution',
'width',
]);

const mediaFeatureNames = uniteSets(deprecatedMediaFeatureNames, rangeTypeMediaFeatureNames, [
'any-hover',
'any-pointer',
'color-gamut',
'color-index',
'display-mode',
'dynamic-range',
'forced-colors',
'grid',
'height',
'hover',
'inverted-colors',
'light-level',
Expand All @@ -43,7 +49,6 @@ const mediaFeatureNames = uniteSets(deprecatedMediaFeatureNames, [
'min-monochrome',
'min-resolution',
'min-width',
'monochrome',
'orientation',
'overflow-block',
'overflow-inline',
Expand All @@ -52,14 +57,13 @@ const mediaFeatureNames = uniteSets(deprecatedMediaFeatureNames, [
'prefers-contrast',
'prefers-reduced-motion',
'prefers-reduced-transparency',
'resolution',
'scan',
'scripting',
'update',
'video-dynamic-range',
'width',
]);

module.exports = {
rangeTypeMediaFeatureNames,
mediaFeatureNames,
};
1 change: 1 addition & 0 deletions lib/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ const rules = {
'media-feature-parentheses-space-inside': importLazy(() =>
require('./media-feature-parentheses-space-inside'),
)(),
'media-feature-range-notation': importLazy(() => require('./media-feature-range-notation'))(),
'media-feature-range-operator-space-after': importLazy(() =>
require('./media-feature-range-operator-space-after'),
)(),
Expand Down
74 changes: 74 additions & 0 deletions lib/rules/media-feature-range-notation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# media-feature-range-notation

Specify context or prefix notation for media feature ranges.

<!-- prettier-ignore -->
```css
@media (width >= 600px) and (min-width: 600px) {}
/** ↑ ↑
* These media feature notations */
```

Media features of the range type can be written using prefixes or the more modern context notation.

Because `min-` and `max-` both equate to range comparisons that include the value, they may be [limiting in certain situations](https://drafts.csswg.org/mediaqueries/#mq-min-max).

## Options

`string`: `"context"|"prefix"`

### `"context"`

Media feature ranges _must always_ use context notation.

The following patterns are considered problems:

<!-- prettier-ignore -->
```css
@media (min-width: 1px) {}
```

<!-- prettier-ignore -->
```css
@media (min-width: 1px) and (max-width: 2px) {}
```

The following patterns are _not_ considered problems:

<!-- prettier-ignore -->
```css
@media (width >= 1px) {}
```

<!-- prettier-ignore -->
```css
@media (1px <= width <= 2px) {}
```

### `"prefix"`

Media feature ranges _must always_ use prefix notation.

The following patterns are considered problems:

<!-- prettier-ignore -->
```css
@media (width >= 1px) {}
```

<!-- prettier-ignore -->
```css
@media (1px <= width <= 2px) {}
```

The following patterns are _not_ considered problems:

<!-- prettier-ignore -->
```css
@media (min-width: 1px) {}
```

<!-- prettier-ignore -->
```css
@media (min-width: 1px) and (max-width: 2px) {}
```
Loading

0 comments on commit 046c576

Please sign in to comment.