Skip to content

Commit

Permalink
Merge pull request ember-cli#45 from OrKoN/linter-configs
Browse files Browse the repository at this point in the history
Added .jshintrc, .jscsrc, .editorconfig
  • Loading branch information
stefanpenner committed Apr 16, 2015
2 parents ea7dfa6 + a53d23b commit 85e12e4
Show file tree
Hide file tree
Showing 9 changed files with 427 additions and 21 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2
60 changes: 60 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"esnext": false,
"excludeFiles": ["node_modules/*"],
"additionalRules": [ "jscs-rules/*.js" ],
"disallowSpacesInsideArrayBrackets": "all",
"disallowMultipleVarDeclWithAssignment": true,
"requireSpaceBeforeObjectValues": true,
"requireCommaBeforeLineBreak": true,
"requireBlocksOnNewline": 1,
"disallowKeywordsOnNewLine": ["else"],
"disallowSpacesBeforeSemicolons": true,
"disallowNewlineBeforeBlockStatements": true,
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"disallowSpacesInCallExpression": true,
"disallowSpacesInsideRoundBracesInCallExpression": true,
"disallowEmptyBlocks": true,
"requireSpacesInsideObjectBrackets": "all",
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireLineFeedAtFileEnd": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"requireSpaceBeforeBlockStatements": true,
"validateIndentation": 2,
"validateParameterSeparator": ", ",
"requireSpaceBeforeKeywords": [
"else",
"while",
"catch"
],
"requireSpaceAfterKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"while",
"with",
"return"
],
"requireSpaceBetweenArguments": true,
"requireSpacesAfterClosingParenthesisInFunctionDeclaration": {
"beforeOpeningRoundBrace": false,
"beforeOpeningCurlyBrace": true
}
}
45 changes: 45 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"predef": [
"console",
"it",
"describe",
"beforeEach",
"afterEach",
"before",
"after",
"-Promise"
],
"expr": true,
"proto": true,
"strict": true,
"indent": 2,
"camelcase": true,
"node": true,
"browser": false,
"boss": true,
"curly": true,
"latedef": "nofunc",
"debug": false,
"devel": false,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": false,
"newcap": true,
"noarg": true,
"noempty": false,
"quotmark": true,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"unused": true,
"sub": true,
"trailing": true,
"white": false,
"eqnull": true,
"esnext": true
}
63 changes: 63 additions & 0 deletions jscs-rules/disallow-multiple-var-decl-with-assignment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
Copyright (c) 2015 Yehuda Katz, Tom Dale and Ember.js contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
taken from https://github.com/emberjs/ember.js
*/

var assert = require('assert');

module.exports = function() {};

module.exports.prototype = {
configure: function(disallowMultipleVarDeclWithAssignment) {
assert(
typeof disallowMultipleVarDeclWithAssignment === 'boolean',
'disallowMultipleVarDeclWithAssignment option requires boolean value'
);
assert(
disallowMultipleVarDeclWithAssignment === true,
'disallowMultipleVarDeclWithAssignment option requires true value or should be removed'
);
},

getOptionName: function() {
return 'disallowMultipleVarDeclWithAssignment';
},

check: function(file, errors) {
file.iterateNodesByType('VariableDeclaration', function(node) {
// allow multiple var declarations in for statement
// for (var i = 0, j = myArray.length; i < j; i++) {}
if (node.parentNode.type === 'ForStatement') { return; }

var hasAssignment = false;
var multiDeclaration = node.declarations.length > 1;

node.declarations.forEach(function(declaration) {
if (declaration.init) { hasAssignment = true; }
});

if (hasAssignment && multiDeclaration) {
errors.add('Multiple assigning variable declarations', node.loc.start);
}
});
}
};
53 changes: 53 additions & 0 deletions jscs-rules/disallow-space-before-semicolon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
Copyright (c) 2015 Yehuda Katz, Tom Dale and Ember.js contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
taken from https://github.com/emberjs/ember.js
*/

var assert = require('assert');

module.exports = function() {};

module.exports.prototype = {
configure: function(disallowSpacesBeforeSemicolons) {
assert(
typeof disallowSpacesBeforeSemicolons === 'boolean',
'disallowSpacesBeforeSemicolons option requires boolean value'
);
assert(
disallowSpacesBeforeSemicolons === true,
'disallowSpacesBeforeSemicolons option requires true value or should be removed'
);
},

getOptionName: function() {
return 'disallowSpacesBeforeSemicolons';
},

check: function(file, errors) {
var lines = file.getLines();
for (var i = 0, l = lines.length; i < l; i++) {
if (lines[i].match(/\s+;$/)) {
errors.add('Spaces are disallowed before semicolons.', i + 1, lines[i].length - 2);
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var assert = require('assert');

function spaceAfterBrace(arg, braceToken) {
if (arg) {
var supportedArgs = arg.type !== 'UnaryExpression' && arg.type !== 'BinaryExpression';

return supportedArgs && braceToken.value === '(' && braceToken.range[1] + 1 === arg.range[0];
}

return false;
}

function spaceBeforeBrace(arg, braceToken) {
if (arg) {
var supportedArgs = arg.type !== 'UnaryExpression' && arg.type !== 'BinaryExpression';

return supportedArgs && braceToken.value === ')' && braceToken.range[0] === arg.range[1] + 1;
}

return false;
}

module.exports = function() {};

module.exports.prototype = {
configure: function(requireSpacesInsideRoundBracesInCallExpression) {
assert(
requireSpacesInsideRoundBracesInCallExpression === true,
'disallowSpacesInsideRoundBracesInCallExpression option requires true value or should be removed'
);
},

getOptionName: function() {
return 'disallowSpacesInsideRoundBracesInCallExpression';
},

check: function(file, errors) {
var tokens = file.getTokens();

file.iterateNodesByType('CallExpression', function(node) {
var nodeBeforeRoundBrace = node;

if (node.callee) {
nodeBeforeRoundBrace = node.callee;
}

var roundBraceTokenStart = file.getTokenByRangeStart(nodeBeforeRoundBrace.range[0]);
var roundBraceTokenEnd = file.getTokenByRangeStart(nodeBeforeRoundBrace.range[0]);

do {
roundBraceTokenStart = file.findNextToken(roundBraceTokenStart, 'Punctuator', '(');
roundBraceTokenEnd = file.findNextToken(roundBraceTokenEnd, 'Punctuator', ')');
} while (roundBraceTokenStart.range[0] < nodeBeforeRoundBrace.range[1]);

var firstArg = nodeBeforeRoundBrace.parentNode.arguments[0];
var lastArg = nodeBeforeRoundBrace.parentNode.arguments[nodeBeforeRoundBrace.parentNode.arguments.length - 1];

var spaceAfterOpeningRoundBraceExists = spaceAfterBrace(firstArg, roundBraceTokenStart);
var spaceBeforeClosingRoundBraceExists = spaceBeforeBrace(lastArg, roundBraceTokenEnd);

if (spaceAfterOpeningRoundBraceExists) {
errors.add(
'Illegal space after opening round brace',
roundBraceTokenStart.loc.start
);
}

if (spaceBeforeClosingRoundBraceExists) {
errors.add(
'Illegal space before closing round brace',
roundBraceTokenEnd.loc.start
);
}
});
}
};
Loading

0 comments on commit 85e12e4

Please sign in to comment.