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

chore: Setup ESLint #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/coverage
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"extends": "eslint:recommended",
"rules": {
"no-unused-expressions": [0],
"no-underscore-dangle": [0],
"no-reserved-keys": [2],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint:recommended already contains this.

"no-multi-spaces": [0],
"no-extra-parens": [2],
"no-unused-vars": [2],
"no-unused-vars": [1],
"no-loop-func": [0],
"key-spacing": [0],
"max-len": [2],
"strict": [0],
"strict": [2],
"indent": [2],
"quotes": [2, "single", "avoid-escape"],
"curly": [0]
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ node_js:
- '0.10'

before_script:
# - 'npm run lint'
- 'npm run lint'

after_script:
- 'npm install [email protected] && cat ./coverage/lcov.info | coveralls'
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function scopify(scope, options) {
* @param {string} scope
*/
function isScopeApplied(selector,scope) {
var selectorTopScope = selector.split(" ",1)[0];
var selectorTopScope = selector.split(' ', 1)[0];
return selectorTopScope === scope;
}

Expand All @@ -74,7 +74,10 @@ function isValidScope(scope) {
function isRuleScopable(rule){

if(rule.parent.type !== 'root') {
if (rule.parent.type === 'atrule' && conditionalGroupRules.indexOf(rule.parent.name) > -1){
if (
rule.parent.type === 'atrule' &&
conditionalGroupRules.indexOf(rule.parent.name) > -1
) {
return true;
}
else {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
"postcss": "^5.0.0"
},
"devDependencies": {
"eslint": "^4.19.1",
"istanbul": "^0.4.5",
"mocha": "^3.0.2"
},
"scripts": {
"lint": "eslint **/*.js",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha -- -u exports test/*.js"
}
}
157 changes: 82 additions & 75 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ var postcss = require('postcss');
var scopify = require('..');

function fixture(name) {
return fs.readFileSync('test/fixtures/' + name, 'utf8').trim();
return fs.readFileSync('test/fixtures/' + name, 'utf8').trim();
}

describe('postcss-scopify', function() {
it('scopes all selectors with an id', function() {
var output = postcss()
.use(scopify('#foo'))
.process(fixture('id.css')).css;
var expected = fixture('id.expected.css');
it('scopes all selectors with an id', function() {
var output = postcss()
.use(scopify('#foo'))
.process(fixture('id.css')).css;
var expected = fixture('id.expected.css');

assert.equal(output, expected);
});
assert.equal(output, expected);
});

it('scopes all selectors with a class', function() {
var output = postcss()
.use(scopify('.boo'))
.process(fixture('class.css')).css;
var expected = fixture('class.expected.css');
it('scopes all selectors with a class', function() {
var output = postcss()
.use(scopify('.boo'))
.process(fixture('class.css')).css;
var expected = fixture('class.expected.css');

assert.equal(output, expected);
});
assert.equal(output, expected);
});

it('replaces & selector with a scope', function() {
var output = postcss()
Expand All @@ -35,68 +35,75 @@ describe('postcss-scopify', function() {
assert.equal(output, expected);
});

it('does NOT adds a scope if it already exists', function() {
var output = postcss()
.use(scopify('.boo'))
.process(fixture('exisiting.css')).css;
var expected = fixture('exisiting.expected.css');

assert.equal(output, expected);
});

it('does not allow invliad scopes', function() {
try
{
postcss()
.use(scopify('#foo , #boo'))
.process(fixture('id.css')).css;
}
catch(error){
assert.equal(error.name+'.'+error.reason, 'CssSyntaxError.invalid scope');
}

});

it('treats empty scopes as invalid', function() {
try
{
postcss()
.use(scopify(''))
.process(fixture('id.css')).css;
}
catch(error){
assert.equal(error.name+'.'+error.reason, 'CssSyntaxError.invalid scope');
}

});

// https://github.com/pazams/postcss-scopify/issues/7
it('should not scope keyframe definitions', function() {
var output = postcss()
.use(scopify('#foo'))
.process(fixture('keyframe.css')).css;
var expected = fixture('keyframe.expected.css');

assert.equal(output, expected);
});

it('should not scope at-rules, but do scope their nested rules for conditional groups at-rules only', function() {
var output = postcss()
.use(scopify('.boo'))
.process(fixture('at-rules.css')).css;
var expected = fixture('at-rules.expected.css');

assert.equal(output, expected);
});
it('does NOT adds a scope if it already exists', function() {
var output = postcss()
.use(scopify('.boo'))
.process(fixture('exisiting.css')).css;
var expected = fixture('exisiting.expected.css');

it('should not scope LESS/SASS style nested rules', function() {
var output = postcss()
.use(scopify('.boo'))
.process(fixture('nested.css')).css;
var expected = fixture('nested.expected.css');
assert.equal(output, expected);
});

assert.equal(output, expected);
});
it('does not allow invliad scopes', function() {
try
{
postcss()
.use(scopify('#foo , #boo'))
.process(fixture('id.css')).css;
}
catch(error){
assert.equal(
error.name + '.' + error.reason,
'CssSyntaxError.invalid scope'
);
}

});

it('treats empty scopes as invalid', function() {
try
{
postcss()
.use(scopify(''))
.process(fixture('id.css')).css;
}
catch(error){
assert.equal(
error.name + '.' + error.reason,
'CssSyntaxError.invalid scope'
);
}

});

// https://github.com/pazams/postcss-scopify/issues/7
it('should not scope keyframe definitions', function() {
var output = postcss()
.use(scopify('#foo'))
.process(fixture('keyframe.css')).css;
var expected = fixture('keyframe.expected.css');

assert.equal(output, expected);
});

// eslint-disable-next-line max-len
it('should not scope at-rules, but do scope their nested rules for conditional groups at-rules only', function() {
var output = postcss()
.use(scopify('.boo'))
.process(fixture('at-rules.css')).css;
var expected = fixture('at-rules.expected.css');

assert.equal(output, expected);
});

it('should not scope LESS/SASS style nested rules', function() {
var output = postcss()
.use(scopify('.boo'))
.process(fixture('nested.css')).css;
var expected = fixture('nested.expected.css');

assert.equal(output, expected);
});


});