Skip to content

Commit

Permalink
🎨 Use and fix issues related to gonzales-pe v4.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bgriffith committed Aug 26, 2017
1 parent 2225ed5 commit ebbc426
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 164 deletions.
7 changes: 2 additions & 5 deletions lib/rules/no-mergeable-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ var mergeableNodes = ['atrule', 'include', 'ruleset'],
curLevel = 0,
curSelector = [],
parentSelector = [],
selectorList = [],
syntax = '';
selectorList = [];


/**
Expand Down Expand Up @@ -89,7 +88,6 @@ var checkAtRule = function (atRule) {

/**
* Checks an atRule to see if if it's part of our mergeable at rule list.
* It also checks for Sass syntax as gonzales currently has issues with the syntax
*
* @param {object} node - The current node / atRule part of our selector
* @returns {boolean} Whether this atRule should be merged or not
Expand All @@ -99,7 +97,7 @@ var isMergeableAtRule = function (node) {
node.forEach(function (item) {
// TODO Check back when Gonzales updates to fix this
// Gonzales has issues with nest levels in media queries :(
if (item.is('atkeyword') && validAtRules.indexOf(item.first('ident').content) !== -1 && syntax !== 'sass') {
if (item.is('atkeyword') && validAtRules.indexOf(item.first('ident').content) !== -1) {
isMergeable = true;
}
});
Expand Down Expand Up @@ -181,7 +179,6 @@ module.exports = {
curSelector = [];
parentSelector = [];
selectorList = [];
syntax = ast.syntax;
ast.traverseByType('stylesheet', function (styleSheet) {
traverseBlock(styleSheet, traverseNode);
});
Expand Down
18 changes: 7 additions & 11 deletions lib/rules/no-universal-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ module.exports = {
'detect': function (ast, parser) {
var result = [];

ast.traverseByType('typeSelector', function (typeSelector) {
typeSelector.traverse(function (item) {
if (item.is('ident') && item.content === '*') {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': item.start.line,
'column': item.start.column,
'message': '* (universal) selectors are not allowed',
'severity': parser.severity
});
}
ast.traverseByType('universalSelector', function (node) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': node.start.line,
'column': node.start.column,
'message': '* (universal) selectors are not allowed',
'severity': parser.severity
});
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"fs-extra": "^3.0.1",
"glob": "^7.0.0",
"globule": "^1.0.0",
"gonzales-pe": "3.4.7",
"gonzales-pe": "^4.1.1",
"js-yaml": "^3.5.4",
"lodash.capitalize": "^4.1.0",
"lodash.kebabcase": "^4.0.0",
Expand Down
8 changes: 4 additions & 4 deletions tests/rules/attribute-quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('attribute-quotes - scss', function () {
lint.test(file, {
'attribute-quotes': 1
}, function (data) {
lint.assert.equal(5, data.warningCount);
lint.assert.equal(6, data.warningCount);
done();
});
});
Expand All @@ -26,7 +26,7 @@ describe('attribute-quotes - scss', function () {
}
]
}, function (data) {
lint.assert.equal(7, data.warningCount);
lint.assert.equal(8, data.warningCount);
done();
});
});
Expand All @@ -42,7 +42,7 @@ describe('attribute-quotes - sass', function () {
lint.test(file, {
'attribute-quotes': 1
}, function (data) {
lint.assert.equal(5, data.warningCount);
lint.assert.equal(6, data.warningCount);
done();
});
});
Expand All @@ -56,7 +56,7 @@ describe('attribute-quotes - sass', function () {
}
]
}, function (data) {
lint.assert.equal(7, data.warningCount);
lint.assert.equal(8, data.warningCount);
done();
});
});
Expand Down
3 changes: 1 addition & 2 deletions tests/rules/force-pseudo-nesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ describe('force pseudo nesting - sass', function () {
lint.test(file, {
'force-pseudo-nesting': 1
}, function (data) {
// Should be 6 once the gonzales parse error is fixed see https://github.com/sasstools/sass-lint/issues/271
lint.assert.equal(5, data.warningCount);
lint.assert.equal(6, data.warningCount);
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/rules/no-attribute-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('no attribute selectors - scss', function () {
lint.test(file, {
'no-attribute-selectors': 1
}, function (data) {
lint.assert.equal(18, data.warningCount);
lint.assert.equal(21, data.warningCount);
done();
});
});
Expand All @@ -28,7 +28,7 @@ describe('no attribute selectors - sass', function () {
lint.test(file, {
'no-attribute-selectors': 1
}, function (data) {
lint.assert.equal(18, data.warningCount);
lint.assert.equal(21, data.warningCount);
done();
});
});
Expand Down
6 changes: 2 additions & 4 deletions tests/rules/no-mergeable-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ describe('no mergeable selectors - scss', function () {

});

// 1 less warning than scss syntax as we dont attempt to merge media queries
describe('no mergeable selectors - sass', function () {
var file = lint.file('no-mergeable-selectors.sass');

it('[default]', function (done) {
lint.test(file, {
'no-mergeable-selectors': 1
}, function (data) {
lint.assert.equal(21, data.warningCount);
lint.assert.equal(22, data.warningCount);
done();
});
});

// 1 less warning than scss syntax as we dont attempt to merge media queries
it('[whitelist: div p]', function (done) {
lint.test(file, {
'no-mergeable-selectors': [
Expand All @@ -57,7 +55,7 @@ describe('no mergeable selectors - sass', function () {
}
]
}, function (data) {
lint.assert.equal(20, data.warningCount);
lint.assert.equal(21, data.warningCount);
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/rules/space-around-operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('space around operator - sass', function () {
lint.test(file, {
'space-around-operator': 1
}, function (data) {
lint.assert.equal(88, data.warningCount);
lint.assert.equal(92, data.warningCount);
done();
});
});
Expand All @@ -56,7 +56,7 @@ describe('space around operator - sass', function () {
}
]
}, function (data) {
lint.assert.equal(88, data.warningCount);
lint.assert.equal(94, data.warningCount);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion tests/rules/url-quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('url quotes - scss', function () {
lint.test(file, {
'url-quotes': 1
}, function (data) {
lint.assert.equal(2, data.warningCount);
lint.assert.equal(1, data.warningCount);
done();
});
});
Expand Down
25 changes: 12 additions & 13 deletions tests/sass/attribute-quotes.sass
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ span[lang=pt]
span[lang~=en-us]
color: blue

// TODO currently a parse error in gonzales-pe
// span[lang|="zh"] {color: red;}
// TODO currently a parse error in gonzales-pe
// a[href^=#] {
// background-color: gold;
// }
span[lang|=zh]
color: red

span[class^=main]
background-color: yellow

// TODO currently a parse error in gonzales-pe
// Invalid CSS - must be ident or string
// a[href^=#] {
// background-color: gold;
// }
//
// a[href$=.cn] {
// color: red;
// }
Expand All @@ -43,15 +42,15 @@ span[lang="pt"]
span[lang~="en-us"]
color: blue

// TODO currently a parse error in gonzales-pe
// span[lang|="zh"] {color: red;}
a[href^="#"]
background-color: gold
span[lang|="zh"]
color: red

span[class^="main"]
background-color: yellow

a[href^="#"]
background-color: gold

a[href$=".cn"]
color: red

Expand Down
27 changes: 14 additions & 13 deletions tests/sass/attribute-quotes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ span[lang~=en-us] {
color: blue;
}

// TODO currently a parse error in gonzales-pe
// span[lang|="zh"] {color: red;}

// TODO currently a parse error in gonzales-pe
// a[href^=#] {
// background-color: gold;
// }
span[lang|=zh] {
color: red;
}

span[class^=main] {
background-color: yellow;
}

// TODO currently a parse error in gonzales-pe
// Invalid CSS - must be ident or string
// a[href^=#] {
// background-color: gold;
// }
//
// a[href$=.cn] {
// color: red;
// }
Expand All @@ -51,17 +51,18 @@ span[lang~="en-us"] {
color: blue;
}

// TODO currently a parse error in gonzales-pe
// span[lang|="zh"] {color: red;}

a[href^="#"] {
background-color: gold;
span[lang|="zh"] {
color: red;
}

span[class^="main"] {
background-color: yellow;
}

a[href^="#"] {
background-color: gold;
}

a[href$=".cn"] {
color: red;
}
Expand Down
1 change: 0 additions & 1 deletion tests/sass/extends-before-mixins.sass
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
@extend %waldo
+foo
@extend %qux

9 changes: 4 additions & 5 deletions tests/sass/force-pseudo-nesting.sass
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ p::first-line
color: #ff0000
font-variant: small-caps

// FIXME parsing issue in Gonzales-Pe see https://github.com/sasstools/sass-lint/issues/271
// .parent
// .child
// p::first-line
// color: #ff0000
.parent
.child
p::first-line
color: #ff0000

.parent
.child
Expand Down
16 changes: 8 additions & 8 deletions tests/sass/indentation/indentation-spaces.sass
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ $foo: ('foo': 'bar', 'bar': ('foo': 'bze'))
@if (1 == 1)
content: 'foo'

=bar
content: 'bar'
content: 'baz'
// TODO: Considered invalid Sass - re-evaluate
// =bar
// content: 'bar'
// content: 'baz'
.color
color: rgba(255, 255, 255, 0.3)
Expand Down Expand Up @@ -100,8 +101,7 @@ $colors: (base: (red: #fff, blue: #fff), text: (default: #fff, light: (brap: #98
#unit
margin: 16px

// Gonzales issue with media queries
// .test
// @media (max-width: 800px), (max-height: 600px)
// #unit
// margin: 16px
.test
@media (max-width: 800px), (max-height: 600px)
#unit
margin: 16px
16 changes: 8 additions & 8 deletions tests/sass/indentation/indentation-tabs.sass
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ $foo: ('foo': 'bar', 'bar': ('foo': 'bze'))
@if (1 == 1)
content: 'foo'

=bar
content: 'bar'
content: 'baz'
// TODO: Considered invalid Sass - re-evaluate
// =bar
// content: 'bar'
// content: 'baz'
.color
color: rgba(255, 255, 255, 0.3)
Expand Down Expand Up @@ -100,8 +101,7 @@ $colors: (base: (red: #fff, blue: #fff), text: (default: #fff, light: (brap: #98
#unit
margin: 16px

// Gonzales issue with media queries
// .test
// @media (max-width: 800px), (max-height: 600px)
// #unit
// margin: 16px
.test
@media (max-width: 800px), (max-height: 600px)
#unit
margin: 16px
21 changes: 10 additions & 11 deletions tests/sass/mixins-before-declarations.sass
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@

// added from issue #227 https://github.com/sasstools/sass-lint/issues/227
// FIXME: Currently causes a parse error with gonzales. Ok if mixin is within
// class
// @media (min-width: 50em)
// +hello
//
// @supports (display: flex)
// +hello
//
// @at-root
// +hello
@include hello

@media (min-width: 50em)
+hello

@supports (display: flex)
+hello

@at-root
+hello
Loading

0 comments on commit ebbc426

Please sign in to comment.