Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix multiline mispelled properties #1113

Merged
merged 1 commit into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions lib/rules/no-misspelled-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

var helpers = require('../helpers');
var properties = require('known-css-properties').all;

// Keep track of our properties we need to skip from the gonzales loop
var skipProps = 0;
/**
* Combine the valid property array and the array of extras into a new array
*
Expand Down Expand Up @@ -33,32 +34,30 @@ var generateName = function (baseName, name) {
* @param {Number} propsCounted - The number of properties encountered in our multiline so far
* @returns {Array} Array of objects containing our property and line/col info etc
*/
var buildPartialProperty = function (valBlock, currentProperty, propsCounted) {
var buildPartialProperty = function (valBlock, currentProperty) {
var propList = [];
var propsEncountered = propsCounted;

if (valBlock.contains('declaration')) {
valBlock.forEach('declaration', function (node) {
var prop = node.first('property');
var value = node.first('value');
propsEncountered++;
skipProps++;

if (prop.first().is('ident')) {
if (value.contains('block')) {
propList = propList.concat(
buildPartialProperty(value.first('block'),
{
name: generateName(currentProperty.name, prop.first('ident').content)
},
propsEncountered
}
)
);
}
else {
propList.push({
name: generateName(currentProperty.name, prop.first('ident').content),
line: prop.first().start.line,
col: prop.first().start.column,
propsEncountered: propsEncountered
col: prop.first().start.column
});
}
}
Expand All @@ -74,16 +73,15 @@ module.exports = {
},
'detect': function (ast, parser) {
var result = [];
var toSkip = 0;
var propertyList = getCombinedList(properties, parser.options['extra-properties']);

ast.traverseByType('declaration', function (node) {
var prop = node.first('property');
var containsInterp = prop.contains('interpolation');
// If we've already checked declarations in a multiline we can skip those decs here
if (toSkip) {
toSkip--;
return !toSkip;
if (skipProps) {
skipProps -= 1;
return !skipProps;
}
// make sure our first node within our property is an ident
if (!prop.first() || !prop.first().is('ident')) {
Expand All @@ -102,15 +100,12 @@ module.exports = {
name: curProperty,
line: prop.first('ident').start.line,
col: prop.first('ident').start.column
},
0
}
);
}
// If we have multiline properties
if (fullProperties.length) {
fullProperties.forEach(function (constrProp) {
// Add the number of property declarations we've already checked here so we can skip them
toSkip += constrProp.propsEncountered;
// Check if the property exists in our list
if (propertyList.indexOf(constrProp.name) === -1) {
result = helpers.addUnique(result, {
Expand Down
12 changes: 6 additions & 6 deletions tests/rules/no-misspelled-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('no misspelled properties - scss', function () {
lint.test(file, {
'no-misspelled-properties': 1
}, function (data) {
lint.assert.equal(9, data.warningCount);
lint.assert.equal(14, data.warningCount);
done();
});
});
Expand All @@ -28,7 +28,7 @@ describe('no misspelled properties - scss', function () {
}
]
}, function (data) {
lint.assert.equal(8, data.warningCount);
lint.assert.equal(13, data.warningCount);
done();
});
});
Expand All @@ -45,7 +45,7 @@ describe('no misspelled properties - scss', function () {
}
]
}, function (data) {
lint.assert.equal(7, data.warningCount);
lint.assert.equal(12, data.warningCount);
done();
});
});
Expand All @@ -61,7 +61,7 @@ describe('no misspelled properties - sass', function () {
lint.test(file, {
'no-misspelled-properties': 1
}, function (data) {
lint.assert.equal(9, data.warningCount);
lint.assert.equal(14, data.warningCount);
done();
});
});
Expand All @@ -77,7 +77,7 @@ describe('no misspelled properties - sass', function () {
}
]
}, function (data) {
lint.assert.equal(8, data.warningCount);
lint.assert.equal(13, data.warningCount);
done();
});
});
Expand All @@ -94,7 +94,7 @@ describe('no misspelled properties - sass', function () {
}
]
}, function (data) {
lint.assert.equal(7, data.warningCount);
lint.assert.equal(12, data.warningCount);
done();
});
});
Expand Down
37 changes: 34 additions & 3 deletions tests/sass/no-misspelled-properties.sass
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
$red: #ff0000

.test-failure
@include test
+test
-webkit-transit1on: width 2s
background-sizer: contain
colors: $red
transit1on: width 2s

.test-correct
@include test
+test

-webkit-transition: width 2s
background-size: contain
color: $red
Expand All @@ -21,7 +22,6 @@ $red: #ff0000
.test-vendor
-moz-osx-font-smoothing: auto


.foo
font:
family: fantasy
Expand All @@ -46,3 +46,34 @@ $red: #ff0000

.foo
margin-#{$property-y}: -2 * $hint-arrow-width

// https://github.com/sasstools/sass-lint/issues/1112
=font-test1
font:
family: Arial, sans-serif
style: normal
weight: 300

=font-test2
font:
family: Arial, sans-serif
style: normal
weight: 400

=font-test2
font:
fazily: Arial, sans-serif
style: normal
weght: 400
border:
top:
left:
radius: 5px
right: 6px solid #fff
botom:
right:
radiu: 5px
background:
color: red
background-colr: blue
font-size: 12rem
63 changes: 53 additions & 10 deletions tests/sass/no-misspelled-properties.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ $red: #ff0000;

.test-failure {
@include test;
-webkit-transit1on: width 2s;
background-sizer: contain;
colors: $red;
transit1on: width 2s;
-webkit-transit1on: width 2s; // 1
background-sizer: contain; // 2
colors: $red; // 3
transit1on: width 2s; // 4
}

.test-correct {
Expand Down Expand Up @@ -33,9 +33,9 @@ $red: #ff0000;
}
border: {
top: {
right: 1px solid #fff;
right: 1px solid #fff; // 5
left: {
color: red;
color: red; // 6
}
}
left: 2px solid #000;
Expand All @@ -44,20 +44,63 @@ $red: #ff0000;

.bar {
font: {
famizy: fantasy;
famizy: fantasy; // 7
size: 12px;
}
boder: {
top: {
rigt: 1px solid #fff;
rigt: 1px solid #fff; // 8
left: {
color: red;
color: red; // 9
}
}
left: 2px solid #000;
left: 2px solid #000; // 10
}
}

.foo {
margin-#{$property-y}: -2 * $hint-arrow-width;
}

// https://github.com/sasstools/sass-lint/issues/1112
@mixin font-test1 {
font: {
family: Arial, sans-serif;
style: normal;
weight: 300;
}
}

@mixin font-test2 {
font: {
family: Arial, sans-serif;
style: normal;
weight: 400;
}
}

@mixin font-test2 {
font: {
fazily: Arial, sans-serif; // 11
style: normal;
weght: 400; // 12
}
border: {
top: {
left: {
radius: 5px;
}
}
right: 6px solid #fff;
botom: {
right: {
radiu: 5px; // 13
}
}
}
background: {
color: red;
}
background-colr: blue; // 14
font-size: 12rem;
}