Skip to content

Commit 50e21f5

Browse files
authored
Merge pull request #1123 from sasstools/v1-dev
v1.12.0
2 parents cca399c + 978dbd8 commit 50e21f5

32 files changed

+544
-67
lines changed

.npmignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.github
2+
coverage
3+
docs
4+
tests
5+
.editorconfig
6+
.eslintrc
7+
.gitignore
8+
.npmignore
9+
.npmrc
10+
.travis.yml
11+
.nvmrc
12+
appveyor.yml
13+
CONTRIBUTING.md
14+
CODE_OF_CONDUCT.md

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Sass Lint Changelog
22

3+
## v1.12.0
4+
5+
**October 3rd, 2017**
6+
7+
**Fixes**
8+
* Fixed an issue with custom properties being flagged in the misspelled-properties rule [#1122](https://github.com/sasstools/sass-lint/pull/1122)
9+
* Fixed an issue where custom properties with colors in their name would be flagged as invalid by no-color-keywords [#1124](https://github.com/sasstools/sass-lint/pull/1124)
10+
* Fixed a crash in empty-line-between-blocks where acessing the content of a parent node of type string would throw an error [#1125](https://github.com/sasstools/sass-lint/pull/1125)
11+
* Functions and custom properties were being incorrectly flagged as invalid within rgba functions for no-color-literals [#1127](https://github.com/sasstools/sass-lint/pull/1127)
12+
* Fixed an incorrect warning in space-after-colon when using `@at-root` [#1129](https://github.com/sasstools/sass-lint/pull/1129)
13+
* Fixed an issue where interpolation was incorrectly flagging within the class-name-format rule [#1131](https://github.com/sasstools/sass-lint/pull/1131)
14+
15+
16+
**New Features**
17+
* Rollup.js integration added to integration list
18+
* Added an npmignore to remove unnecessary dev files from a sass-lint install / release [#1132](https://github.com/sasstools/sass-lint/pull/1132)
19+
* Added basic support for a `.sasslintrc` json config file [#1135](https://github.com/sasstools/sass-lint/pull/1135)
20+
* Added two new options to the variable-for-property rule - [allow-map-get](https://github.com/sasstools/sass-lint/blob/master/docs/rules/variable-for-property.md#allow-map-get-true) & [allowed-functions](https://github.com/sasstools/sass-lint/blob/master/docs/rules/variable-for-property.md#allowed-functions-) - [#1128](https://github.com/sasstools/sass-lint/pull/1128)
21+
322
## v1.11.1
423

524
**August 28th, 2017**

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ npm install sass-lint --save-dev
2121

2222
## Configuring
2323

24-
Sass-lint can be configured from a `.sass-lint.yml` file in your project. If you don't have one in the root of your project or you would like all your projects to follow a standard config file then you can specify the path to one in your project's `package.json` file.
24+
Sass-lint can be configured from a `.sass-lint.yml` or `.sasslintrc` file in your project. The `.sasslintrc` file can be in either JSON format or YAML. Both formats are interchangeable easily using tools such as [json2yaml](https://www.json2yaml.com/). If you don't either file in the root of your project or you would like all your projects to follow a standard config file then you can specify the path to one in your project's `package.json` file with the `sasslintConfig` option.
2525

2626
For example:
2727
```javascript
@@ -32,7 +32,7 @@ For example:
3232
}
3333
```
3434

35-
Use the [Sample Config](https://github.com/sasstools/sass-lint/tree/master/docs/sass-lint.yml) as a guide to create your own `.sass-lint.yml` config file. The default configuration can be found [here](https://github.com/sasstools/sass-lint/blob/master/lib/config/sass-lint.yml).
35+
Use the [Sample Config (YAML)](https://github.com/sasstools/sass-lint/tree/master/docs/sass-lint.yml) or [Sample Config (JSON)](https://github.com/sasstools/sass-lint/tree/master/docs/sasslintrc) as a guide to create your own config file. The default configuration can be found [here](https://github.com/sasstools/sass-lint/blob/master/lib/config/sass-lint.yml).
3636

3737
### [Configuration Documentation](https://github.com/sasstools/sass-lint/tree/master/docs/options)
3838

@@ -48,7 +48,6 @@ The following are options that you can use to config the Sass Linter.
4848
* [merge-default-rules](https://github.com/sasstools/sass-lint/tree/master/docs/options/merge-default-rules.md) - Allows you to merge your rules with the default config file included with sass-lint
4949
* [output-file](https://github.com/sasstools/sass-lint/tree/master/docs/options/output-file.md) - Choose to write the linters output to a file
5050

51-
5251
#### Files
5352

5453
The `files` option contains two properties, `include` and `ignore`. Both can be set to either a [glob](https://github.com/isaacs/node-glob) or an array of glob strings/file paths depending on your projects' needs and setup.
@@ -284,6 +283,10 @@ Our AST is [Gonzales-PE](https://github.com/tonyganch/gonzales-pe/tree/dev). Eac
284283
* [Gulp](https://www.npmjs.com/package/gulp-sass-lint)
285284
* [Grunt](https://github.com/sasstools/grunt-sass-lint)
286285

286+
## Module Bundler Integration
287+
288+
* [rollup.js](https://github.com/kopacki/rollup-plugin-sass-lint)
289+
287290
## IDE Integration
288291

289292
* [Atom](https://atom.io/packages/linter-sass-lint)

docs/rules/variable-for-property.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ The `!important` flag will also be excluded when used.
1414

1515
* `properties`: `[array of property names]` (defaults to empty array `[]`)
1616

17+
* `allow-map-get`: `true`/`false` (defaults to `true`) You may allow/disallow the use of `map-get()` as property values
18+
19+
* `allowed-functions`: `[array of function names]` (defaults to empty array `[]`)
20+
1721
You may pass an array of properties you wish to enforce the use of variables for
1822

1923
```yaml
@@ -26,10 +30,54 @@ variable-for-property:
2630
- 'content'
2731
```
2832
33+
You may pass an array of function names you wish to allow as property values
34+
35+
```yaml
36+
37+
variable-for-property:
38+
- 1
39+
-
40+
'allowed-functions':
41+
- 'my-map-func'
42+
- 'palette'
43+
```
44+
45+
*** full config example ***
46+
47+
```yaml
48+
variable-for-property:
49+
- 1
50+
-
51+
allow-map-get: true
52+
allowed-functions:
53+
- my-map-func
54+
- palette
55+
properties:
56+
- margin
57+
- content
58+
```
59+
2960
## Examples
3061
3162
By default `properties` is an empty array and therefore no properties are forced to use variables as values.
3263

64+
```scss
65+
.bar {
66+
content: ' ';
67+
margin: 0;
68+
69+
&__element {
70+
margin: 0;
71+
}
72+
}
73+
74+
@mixin red() {
75+
margin: 0;
76+
}
77+
```
78+
79+
## [properties: []]
80+
3381
When `properties` contains the values shown in the options section example the following would be disallowed:
3482

3583
```scss
@@ -65,6 +113,53 @@ When `properties` contains the values shown in the options section example the f
65113
66114
```
67115

116+
## [allow-map-get: true]
117+
118+
When allow-map-get is set to `true` and properties contains the `color` property, the following would be allowed
119+
120+
```scss
121+
.foo {
122+
color: map-get(blueish, light);
123+
}
124+
```
125+
126+
When allow-map-get is set to `false` and properties contains the `color` property, the following would be disallowed
127+
128+
```scss
129+
.foo {
130+
color: map-get(blueish, light);
131+
}
132+
```
133+
134+
## [allowed-functions: []]
135+
136+
When `allowed-functions` contains the values shown in the options section and `properties` includes the `color` property the following would be disallowed:
137+
138+
```scss
139+
.foo {
140+
color: disallowed-function($test, $vars);
141+
142+
&__element {
143+
color: invalid-func-name($test, $vars);
144+
}
145+
}
146+
```
147+
148+
When `allowed-functions` contains the values shown in the options section and `properties` includes the `color` property the following would be disallowed:
149+
150+
```scss
151+
.foo {
152+
color: my-map-func($allowed);
153+
154+
&__element {
155+
color: palette(blue, light);
156+
}
157+
}
158+
159+
```
160+
161+
## Extra info
162+
68163
The `!important` flag will be excluded from any lint warnings.
69164

70165
For example if `properties` contains the value `color` the following would be disallowed

lib/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ module.exports = function (options, configPath) {
5252
}
5353
else {
5454
configPath = confHelpers.findFile(false, '.sass-lint.yml');
55+
56+
if (!configPath) {
57+
configPath = confHelpers.findFile(false, '.sasslintrc');
58+
}
5559
}
5660
}
5761
else if (!pathIsAbsolute(configPath)) {

lib/helpers.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ helpers.attemptTraversal = function (node, traversalPath) {
309309
currentNodeList = [],
310310
processChildNode = function processChildNode (child) {
311311
child.forEach(traversalPath[i], function (n) {
312-
nextNodeList.push(n);
312+
if (n.content && typeof n.content !== 'string' && n.contains('interpolation')) {
313+
return false;
314+
}
315+
return nextNodeList.push(n);
313316
});
314317
};
315318

lib/rules/empty-line-between-blocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var findNearestReturnSCSS = function (parent, i) {
5252
var findNearestReturnSass = function (parent, i) {
5353
var previous;
5454

55-
if (parent.content[i - 1]) {
55+
if (!parent.is('ident') && parent.content[i - 1]) {
5656
previous = parent.content[i - 1];
5757

5858
if (counter === 2) {

lib/rules/no-color-keywords.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ var cssColors = yaml.safeLoad(fs.readFileSync(path.join(__dirname, '../../data',
1515
* @returns {boolean} Whether the node is a valid type or not
1616
*/
1717
var checkValidParentType = function (node) {
18-
if (node) {
19-
return node.type === 'function' || node.type === 'variable';
18+
if (node && (node.is('function') || node.is('variable') || node.is('customProperty'))) {
19+
return false;
2020
}
2121

22-
return false;
22+
return true;
2323
};
2424

2525
module.exports = {
@@ -30,7 +30,7 @@ module.exports = {
3030

3131
ast.traverseByType('value', function (node) {
3232
node.traverse(function (elem, i, parent) {
33-
if (elem.type === 'ident' && !checkValidParentType(parent)) {
33+
if (elem.type === 'ident' && checkValidParentType(parent)) {
3434
var index = cssColors.indexOf(elem.content.toLowerCase());
3535

3636
if (index !== -1) {

lib/rules/no-color-literals.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = {
8080

8181
ast.traverseByTypes(['value', 'variable'], function (node, i, parent) {
8282

83-
// If we don't literals as variable names then check each variable name
83+
// If we don't allow literals as variable names then check each variable name
8484
if (node.is('variable') && !parser.options['allow-variable-identifiers']) {
8585
if (cssColors.indexOf(node.content[0].content) !== -1) {
8686
result = helpers.addUnique(result, {
@@ -127,15 +127,18 @@ module.exports = {
127127
// if rgba usage is allowed we need to make sure only variables are being passed to it.
128128
else if (
129129
parser.options['allow-rgba'] &&
130-
funcType === 'rgba' &&
131-
valElem.content[1].content[0].type !== 'variable' &&
130+
funcType === 'rgba' && (
131+
valElem.content[1].content[0].type !== 'variable' &&
132+
valElem.content[1].content[0].type !== 'function' &&
133+
valElem.content[1].content[0].type !== 'customProperty'
134+
) &&
132135
declarationType !== 'variable'
133136
) {
134137
result = helpers.addUnique(result, {
135138
'ruleId': parser.rule.name,
136139
'line': valElem.start.line,
137140
'column': valElem.start.column,
138-
'message': 'A color in variable form must be passed to rgba, literals are restricted',
141+
'message': 'Only variables or functions must be passed to rgba, literals are restricted',
139142
'severity': parser.severity
140143
});
141144
}

lib/rules/no-misspelled-properties.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var buildPartialProperty = function (valBlock, currentProperty) {
4343
var value = node.first('value');
4444
skipProps++;
4545

46-
if (prop.first().is('ident')) {
46+
if (prop && prop.first().is('ident')) {
4747
if (value.contains('block')) {
4848
propList = propList.concat(
4949
buildPartialProperty(value.first('block'),
@@ -77,7 +77,10 @@ module.exports = {
7777

7878
ast.traverseByType('declaration', function (node) {
7979
var prop = node.first('property');
80-
var containsInterp = prop.contains('interpolation');
80+
// declaration may include custom properties etc, check that prop is defined here
81+
if (!prop) {
82+
return false;
83+
}
8184
// If we've already checked declarations in a multiline we can skip those decs here
8285
if (skipProps) {
8386
skipProps -= 1;
@@ -123,7 +126,7 @@ module.exports = {
123126
* If our property name contains interpolation we need to make a best guess by using a
124127
* partial string match as we can't be 100% on the context
125128
*/
126-
if (containsInterp) {
129+
if (prop.contains('interpolation')) {
127130
if (!helpers.isPartialStringMatch(curProperty, propertyList)) {
128131
result = helpers.addUnique(result, {
129132
'ruleId': parser.rule.name,

0 commit comments

Comments
 (0)