Skip to content

Commit

Permalink
Merge pull request #1123 from sasstools/v1-dev
Browse files Browse the repository at this point in the history
v1.12.0
  • Loading branch information
DanPurdy authored Oct 3, 2017
2 parents cca399c + 978dbd8 commit 50e21f5
Show file tree
Hide file tree
Showing 32 changed files with 544 additions and 67 deletions.
14 changes: 14 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.github
coverage
docs
tests
.editorconfig
.eslintrc
.gitignore
.npmignore
.npmrc
.travis.yml
.nvmrc
appveyor.yml
CONTRIBUTING.md
CODE_OF_CONDUCT.md
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Sass Lint Changelog

## v1.12.0

**October 3rd, 2017**

**Fixes**
* Fixed an issue with custom properties being flagged in the misspelled-properties rule [#1122](https://github.com/sasstools/sass-lint/pull/1122)
* 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)
* 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)
* 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)
* Fixed an incorrect warning in space-after-colon when using `@at-root` [#1129](https://github.com/sasstools/sass-lint/pull/1129)
* Fixed an issue where interpolation was incorrectly flagging within the class-name-format rule [#1131](https://github.com/sasstools/sass-lint/pull/1131)


**New Features**
* Rollup.js integration added to integration list
* Added an npmignore to remove unnecessary dev files from a sass-lint install / release [#1132](https://github.com/sasstools/sass-lint/pull/1132)
* Added basic support for a `.sasslintrc` json config file [#1135](https://github.com/sasstools/sass-lint/pull/1135)
* 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)

## v1.11.1

**August 28th, 2017**
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm install sass-lint --save-dev

## Configuring

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.
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.

For example:
```javascript
Expand All @@ -32,7 +32,7 @@ For example:
}
```

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).
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).

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

Expand All @@ -48,7 +48,6 @@ The following are options that you can use to config the Sass Linter.
* [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
* [output-file](https://github.com/sasstools/sass-lint/tree/master/docs/options/output-file.md) - Choose to write the linters output to a file


#### Files

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.
Expand Down Expand Up @@ -284,6 +283,10 @@ Our AST is [Gonzales-PE](https://github.com/tonyganch/gonzales-pe/tree/dev). Eac
* [Gulp](https://www.npmjs.com/package/gulp-sass-lint)
* [Grunt](https://github.com/sasstools/grunt-sass-lint)

## Module Bundler Integration

* [rollup.js](https://github.com/kopacki/rollup-plugin-sass-lint)

## IDE Integration

* [Atom](https://atom.io/packages/linter-sass-lint)
Expand Down
95 changes: 95 additions & 0 deletions docs/rules/variable-for-property.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ The `!important` flag will also be excluded when used.

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

* `allow-map-get`: `true`/`false` (defaults to `true`) You may allow/disallow the use of `map-get()` as property values

* `allowed-functions`: `[array of function names]` (defaults to empty array `[]`)

You may pass an array of properties you wish to enforce the use of variables for

```yaml
Expand All @@ -26,10 +30,54 @@ variable-for-property:
- 'content'
```
You may pass an array of function names you wish to allow as property values
```yaml

variable-for-property:
- 1
-
'allowed-functions':
- 'my-map-func'
- 'palette'
```
*** full config example ***
```yaml
variable-for-property:
- 1
-
allow-map-get: true
allowed-functions:
- my-map-func
- palette
properties:
- margin
- content
```
## Examples
By default `properties` is an empty array and therefore no properties are forced to use variables as values.

```scss
.bar {
content: ' ';
margin: 0;
&__element {
margin: 0;
}
}
@mixin red() {
margin: 0;
}
```

## [properties: []]

When `properties` contains the values shown in the options section example the following would be disallowed:

```scss
Expand Down Expand Up @@ -65,6 +113,53 @@ When `properties` contains the values shown in the options section example the f
```

## [allow-map-get: true]

When allow-map-get is set to `true` and properties contains the `color` property, the following would be allowed

```scss
.foo {
color: map-get(blueish, light);
}
```

When allow-map-get is set to `false` and properties contains the `color` property, the following would be disallowed

```scss
.foo {
color: map-get(blueish, light);
}
```

## [allowed-functions: []]

When `allowed-functions` contains the values shown in the options section and `properties` includes the `color` property the following would be disallowed:

```scss
.foo {
color: disallowed-function($test, $vars);
&__element {
color: invalid-func-name($test, $vars);
}
}
```

When `allowed-functions` contains the values shown in the options section and `properties` includes the `color` property the following would be disallowed:

```scss
.foo {
color: my-map-func($allowed);
&__element {
color: palette(blue, light);
}
}
```

## Extra info

The `!important` flag will be excluded from any lint warnings.

For example if `properties` contains the value `color` the following would be disallowed
Expand Down
4 changes: 4 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ module.exports = function (options, configPath) {
}
else {
configPath = confHelpers.findFile(false, '.sass-lint.yml');

if (!configPath) {
configPath = confHelpers.findFile(false, '.sasslintrc');
}
}
}
else if (!pathIsAbsolute(configPath)) {
Expand Down
5 changes: 4 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ helpers.attemptTraversal = function (node, traversalPath) {
currentNodeList = [],
processChildNode = function processChildNode (child) {
child.forEach(traversalPath[i], function (n) {
nextNodeList.push(n);
if (n.content && typeof n.content !== 'string' && n.contains('interpolation')) {
return false;
}
return nextNodeList.push(n);
});
};

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/empty-line-between-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var findNearestReturnSCSS = function (parent, i) {
var findNearestReturnSass = function (parent, i) {
var previous;

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

if (counter === 2) {
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/no-color-keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ var cssColors = yaml.safeLoad(fs.readFileSync(path.join(__dirname, '../../data',
* @returns {boolean} Whether the node is a valid type or not
*/
var checkValidParentType = function (node) {
if (node) {
return node.type === 'function' || node.type === 'variable';
if (node && (node.is('function') || node.is('variable') || node.is('customProperty'))) {
return false;
}

return false;
return true;
};

module.exports = {
Expand All @@ -30,7 +30,7 @@ module.exports = {

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

if (index !== -1) {
Expand Down
11 changes: 7 additions & 4 deletions lib/rules/no-color-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = {

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

// If we don't literals as variable names then check each variable name
// If we don't allow literals as variable names then check each variable name
if (node.is('variable') && !parser.options['allow-variable-identifiers']) {
if (cssColors.indexOf(node.content[0].content) !== -1) {
result = helpers.addUnique(result, {
Expand Down Expand Up @@ -127,15 +127,18 @@ module.exports = {
// if rgba usage is allowed we need to make sure only variables are being passed to it.
else if (
parser.options['allow-rgba'] &&
funcType === 'rgba' &&
valElem.content[1].content[0].type !== 'variable' &&
funcType === 'rgba' && (
valElem.content[1].content[0].type !== 'variable' &&
valElem.content[1].content[0].type !== 'function' &&
valElem.content[1].content[0].type !== 'customProperty'
) &&
declarationType !== 'variable'
) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': valElem.start.line,
'column': valElem.start.column,
'message': 'A color in variable form must be passed to rgba, literals are restricted',
'message': 'Only variables or functions must be passed to rgba, literals are restricted',
'severity': parser.severity
});
}
Expand Down
9 changes: 6 additions & 3 deletions lib/rules/no-misspelled-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var buildPartialProperty = function (valBlock, currentProperty) {
var value = node.first('value');
skipProps++;

if (prop.first().is('ident')) {
if (prop && prop.first().is('ident')) {
if (value.contains('block')) {
propList = propList.concat(
buildPartialProperty(value.first('block'),
Expand Down Expand Up @@ -77,7 +77,10 @@ module.exports = {

ast.traverseByType('declaration', function (node) {
var prop = node.first('property');
var containsInterp = prop.contains('interpolation');
// declaration may include custom properties etc, check that prop is defined here
if (!prop) {
return false;
}
// If we've already checked declarations in a multiline we can skip those decs here
if (skipProps) {
skipProps -= 1;
Expand Down Expand Up @@ -123,7 +126,7 @@ module.exports = {
* If our property name contains interpolation we need to make a best guess by using a
* partial string match as we can't be 100% on the context
*/
if (containsInterp) {
if (prop.contains('interpolation')) {
if (!helpers.isPartialStringMatch(curProperty, propertyList)) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
Expand Down
45 changes: 23 additions & 22 deletions lib/rules/space-after-colon.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,30 @@ module.exports = {
var result = [];

ast.traverseByTypes(['propertyDelimiter', 'operator'], function (delimiter, i, parent) {
if (delimiter.content === ':') {
var next = parent.content[i + 1];

if (next && next.is('space')) {
if (!parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': next.start.line,
'column': next.start.column,
'message': 'No space allowed after `:`',
'severity': parser.severity
});
if (!parent.is('atrule')) {
if (delimiter.content === ':') {
var next = parent.content[i + 1];
if (next && next.is('space')) {
if (!parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': next.start.line,
'column': next.start.column,
'message': 'No space allowed after `:`',
'severity': parser.severity
});
}
}
}
else {
if (parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': delimiter.start.line,
'column': delimiter.start.column,
'message': 'Space expected after `:`',
'severity': parser.severity
});
else {
if (parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': delimiter.start.line,
'column': delimiter.start.column,
'message': 'Space expected after `:`',
'severity': parser.severity
});
}
}
}
}
Expand Down
Loading

0 comments on commit 50e21f5

Please sign in to comment.