Skip to content

Commit

Permalink
Merge branch 'master' into browser-bundle
Browse files Browse the repository at this point in the history
# By Mike Allanson (6) and others
# Via GitHub
* master:
  Bump got from 11.2.0 to 11.3.0 (#4825)
  Export an object from the CSS-in-JS syntax (#4824)
  Add type `Formatter` for formatter functions (#4823)
  Update CHANGELOG.md
  Fix false positives for namespaced variables in property-no-unknown (#4803)
  Update CHANGELOG.md
  Fix TypeError for inline comments and autofix for sugarss in max-empty-lines (#4821)
  Create new 'lintPostcssResult' module (#4819)
  13.6.0
  Update deps
  Prepare 13.6.0
  Update CHANGELOG.md
  • Loading branch information
m-allanson committed Jun 10, 2020
2 parents 92904dc + 4a4ea84 commit ae22a5c
Show file tree
Hide file tree
Showing 14 changed files with 388 additions and 127 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.md
Expand Up @@ -4,11 +4,16 @@ All notable changes to this project are documented in this file.

## Head

- Fixed: `max-empty-lines` TypeError from inline comment with autofix and sugarss syntax ([#4821](https://github.com/stylelint/stylelint/pull/4821)).
- Fixed: `property-no-unknown` false positives for namespaced variables ([#4803](https://github.com/stylelint/stylelint/pull/4803)).

## 13.6.0

- Added: `ignoreSelectors[]` to `block-opening-brace-space-before` ([#4640](https://github.com/stylelint/stylelint/pull/4640)).
- Fixed: false positives for all scope disables in `--report-invalid-scope-disables ([#4784](https://github.com/stylelint/stylelint/pull/4784))
- Fixed: workaround CSS-in-JS syntax throws a TypeError in the following conditions: 1. encounter a call or template expression named 'html' and 2. syntax loads via `autoSyntax()`.
- Fixed: specify minimum node version in `package.json`'s `engine` field ([#4790](https://github.com/stylelint/stylelint/pull/4790)).
- Fixed: write error information to `stderr` ([#4799](https://github.com/stylelint/stylelint/pull/4799)).
- Fixed: false positives for all scope disables in `--report-invalid-scope-disables` ([#4784](https://github.com/stylelint/stylelint/pull/4784)).
- Fixed: TypeError for CSS-in-JS when encountering a call or template expression named 'html' ([#4797](https://github.com/stylelint/stylelint/pull/4797)).
- Fixed: writing error information to `stderr` ([#4799](https://github.com/stylelint/stylelint/pull/4799)).
- Fixed: minimum node version in `package.json`'s `engine` field ([#4790](https://github.com/stylelint/stylelint/pull/4790)).
- Fixed: `alpha-value-notation` number precision errors ([#4802](https://github.com/stylelint/stylelint/pull/4802)).
- Fixed: `font-family-no-missing-generic-family-keyword` false positives for variables ([#4806](https://github.com/stylelint/stylelint/pull/4806)).
- Fixed: `no-duplicate-selectors` false positives for universal selector and `disallowInList` ([#4809](https://github.com/stylelint/stylelint/pull/4809)).
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-guide/formatters.md
Expand Up @@ -11,7 +11,7 @@ function formatter(results, returnValue) {
}
```

Where the argument (`results`) is an array of stylelint result objects (type `Array<StylelintResult>`) in the form:
Where the first argument (`results`) is an array of stylelint result objects (type `Array<StylelintResult>`) in the form:

```js
// A stylelint result object
Expand Down
44 changes: 44 additions & 0 deletions lib/rules/max-empty-lines/__tests__/index.js
Expand Up @@ -478,6 +478,50 @@ testRule({
],
});

testRule({
ruleName,
config: [2],
skipBasicChecks: true,
syntax: 'sugarss',
fix: true,

accept: [
{
code: '\n\n// one',
},
{
code: '// one\n\n',
},
{
code: '// one\n\n\n// two\n',
},
],

reject: [
{
code: '\n\n\n// one',
fixed: '\n\n// one',
message: messages.expected(2),
line: 3,
column: 1,
},
{
code: '// one\n\n\n',
fixed: '// one\n\n',
message: messages.expected(2),
line: 4,
column: 1,
},
{
code: '// one\n\n\n\n// two\n',
fixed: '// one\n\n\n// two\n',
message: messages.expected(2),
line: 4,
column: 1,
},
],
});

testRule({
ruleName,
config: [2, { ignore: 'comments' }],
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/max-empty-lines/index.js
Expand Up @@ -154,7 +154,7 @@ function rule(max, options, context) {
function replaceEmptyLines(max, str, isSpecialCase = false) {
const repeatTimes = isSpecialCase ? max : max + 1;

if (repeatTimes === 0) {
if (repeatTimes === 0 || typeof str !== 'string') {
return '';
}

Expand Down
4 changes: 4 additions & 0 deletions lib/rules/property-no-unknown/__tests__/index.js
Expand Up @@ -86,6 +86,10 @@ testRule({
code: '.foo { $bgColor: white; }',
description: 'ignore SCSS variables',
},
{
code: '.foo { namespace.$bgColor: white; }',
description: 'ignore SCSS variables within namespace',
},
{
code: '.foo { #{$prop}: black; }',
description: 'ignore property interpolation',
Expand Down
36 changes: 36 additions & 0 deletions lib/utils/__tests__/isScssVariable.test.js
@@ -0,0 +1,36 @@
'use strict';

const isScssVariable = require('../isScssVariable');

describe('isScssVariable', () => {
it('sass variable', () => {
expect(isScssVariable('$sass-variable')).toBeTruthy();
});
it('sass variable within namespace', () => {
expect(isScssVariable('namespace.$sass-variable')).toBeTruthy();
});
it('sass interpolation', () => {
expect(isScssVariable('#{$Attr}-color')).toBeFalsy();
});
it('single word property', () => {
expect(isScssVariable('top')).toBeFalsy();
});
it('hyphenated property', () => {
expect(isScssVariable('border-top-left-radius')).toBeFalsy();
});
it('property with vendor prefix', () => {
expect(isScssVariable('-webkit-appearance')).toBeFalsy();
});
it('custom property', () => {
expect(isScssVariable('--custom-property')).toBeFalsy();
});
it('less variable', () => {
expect(isScssVariable('@var')).toBeFalsy();
});
it('less append property value with comma', () => {
expect(isScssVariable('transform+')).toBeFalsy();
});
it('less append property value with space', () => {
expect(isScssVariable('transform+_')).toBeFalsy();
});
});
12 changes: 12 additions & 0 deletions lib/utils/__tests__/isStandardSyntaxDeclaration.test.js
Expand Up @@ -121,6 +121,18 @@ describe('isStandardSyntaxDeclaration', () => {
});
});

it('scss var within namespace', () => {
scssDecls('namespace.$var: b', (decl) => {
expect(isStandardSyntaxDeclaration(decl)).toBeFalsy();
});
});

it('nested scss var within namespace', () => {
scssDecls('a { namespace.$var: b }', (decl) => {
expect(isStandardSyntaxDeclaration(decl)).toBeFalsy();
});
});

it('sass list', () => {
sassDecls('$list: (key: value, key2: value2)', (decl) => {
expect(isStandardSyntaxDeclaration(decl)).toBeFalsy();
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/__tests__/isStandardSyntaxProperty.test.js
Expand Up @@ -18,6 +18,9 @@ describe('isStandardSyntaxProperty', () => {
it('sass variable', () => {
expect(isStandardSyntaxProperty('$sass-variable')).toBeFalsy();
});
it('sass variable within namespace', () => {
expect(isStandardSyntaxProperty('namespace.$sass-variable')).toBeFalsy();
});
it('sass interpolation', () => {
expect(isStandardSyntaxProperty('#{$Attr}-color')).toBeFalsy();
});
Expand Down
21 changes: 21 additions & 0 deletions lib/utils/isScssVariable.js
@@ -0,0 +1,21 @@
'use strict';

/**
* Check whether a property is SCSS variable
*
* @param {string} property
* @returns {boolean}
*/
module.exports = function (property) {
// SCSS var (e.g. $var: x), list (e.g. $list: (x)) or map (e.g. $map: (key:value))
if (property.startsWith('$')) {
return true;
}

// SCSS var within a namespace (e.g. namespace.$var: x)
if (property.includes('.$')) {
return true;
}

return false;
};
5 changes: 3 additions & 2 deletions lib/utils/isStandardSyntaxDeclaration.js
@@ -1,5 +1,6 @@
'use strict';

const isScssVariable = require('./isScssVariable');
const { isRoot } = require('./typeGuards');

/**
Expand Down Expand Up @@ -29,8 +30,8 @@ module.exports = function (decl) {
return false;
}

// Sass var (e.g. $var: x), nested list (e.g. $list: (x)) or nested map (e.g. $map: (key:value))
if (prop[0] === '$') {
// SCSS var
if (isScssVariable(prop)) {
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/utils/isStandardSyntaxProperty.js
@@ -1,6 +1,7 @@
'use strict';

const hasInterpolation = require('../utils/hasInterpolation');
const isScssVariable = require('./isScssVariable');

/**
* Check whether a property is standard
Expand All @@ -9,8 +10,8 @@ const hasInterpolation = require('../utils/hasInterpolation');
* @returns {boolean}
*/
module.exports = function (property) {
// SCSS var (e.g. $var: x), list (e.g. $list: (x)) or map (e.g. $map: (key:value))
if (property.startsWith('$')) {
// SCSS var
if (isScssVariable(property)) {
return false;
}

Expand Down

0 comments on commit ae22a5c

Please sign in to comment.