eslint-plugin-ember-suave
Advanced tools
Comparing version
'use strict'; | ||
module.exports = { | ||
root: true, | ||
parserOptions: { | ||
ecmaVersion: 6, | ||
sourceType: 'module' | ||
}, | ||
parser: 'babel-eslint', | ||
env: { | ||
'browser': true | ||
}, | ||
plugins: [ | ||
@@ -9,12 +18,20 @@ 'ember-suave' | ||
// Built-in Rules | ||
'no-empty': 'error', | ||
'array-bracket-spacing': ['error', 'never'], | ||
'arrow-parens': ['error', 'always'], | ||
'brace-style': ['error', '1tbs', { | ||
'allowSingleLine': false | ||
}], | ||
'no-multiple-empty-lines': 'error', | ||
'one-var': ['error', { | ||
'uninitialized': 'always', | ||
'initialized': 'never' | ||
'camelcase': ['error', { | ||
'properties': 'always' | ||
}], | ||
'operator-linebreak': ['error', 'before'], | ||
'comma-dangle': ['error', 'never'], | ||
'comma-spacing': ['error', { 'before': false, 'after': true }], | ||
'comma-style': ['error', 'last'], | ||
'curly': ['error', 'all'], | ||
'dot-notation': 'error', | ||
'dot-location': ['error', 'property'], | ||
'generator-star-spacing': ['error', {'before': false}], | ||
'indent': ['error', 2, { | ||
'SwitchCase': 1 | ||
}], | ||
'key-spacing': ['error', { | ||
@@ -24,40 +41,39 @@ 'beforeColon': false, | ||
}], | ||
'space-unary-ops': ['error', { | ||
'words': false, | ||
'nonwords': false | ||
'keyword-spacing': ['error', {'overrides': {'catch': {'after': false}}}], | ||
'max-statements-per-line': ['error', { 'max': 1 }], | ||
'new-cap': 'error', | ||
'no-empty': 'error', | ||
'no-multiple-empty-lines': ['error', { | ||
'max': 1 | ||
}], | ||
'semi-spacing': ['error', { | ||
'before': false, | ||
'after': true | ||
}], | ||
'space-before-function-paren': ['error', 'never'], | ||
'space-in-parens': ['error', 'never'], | ||
'no-spaced-func': 'error', | ||
'comma-dangle': ['error', 'never'], | ||
'no-trailing-spaces': 'error', | ||
'no-useless-concat': 'error', | ||
'no-var': 'error', | ||
'camelcase': ['error', { | ||
'properties': 'never' | ||
'object-curly-spacing': ['error', 'always'], | ||
'object-shorthand': ['error', 'always'], | ||
'one-var': ['error', { | ||
'uninitialized': 'always', | ||
'initialized': 'never' | ||
}], | ||
'new-cap': 'error', | ||
'comma-style': ['error', 'last'], | ||
'curly': ['error', 'all'], | ||
'dot-notation': 'error', | ||
'object-shorthand': 'error', | ||
'newline-after-var': ['error', 'always'], | ||
'arrow-parens': 'error', | ||
'semi': ['error', 'always'], | ||
'space-infix-ops': 'error', | ||
'keyword-spacing': 'error', | ||
'spaced-comment': ['error', 'always'], | ||
'space-before-blocks': ['error', 'always'], | ||
'array-bracket-spacing': ['error', 'always'], | ||
'operator-linebreak': ['error', 'before'], | ||
'prefer-spread': 'error', | ||
'prefer-template': 'error', | ||
'indent': ['error', 2, { | ||
'SwitchCase': 1 | ||
}], | ||
'quotes': ['error', 'single', { | ||
'avoidEscape': true | ||
}], | ||
'semi': ['error', 'always'], | ||
'semi-spacing': ['error', { | ||
'before': false, | ||
'after': true | ||
}], | ||
'space-before-blocks': ['error', 'always'], | ||
'space-before-function-paren': ['error', 'never'], | ||
'space-in-parens': ['error', 'never'], | ||
'space-infix-ops': 'error', | ||
'space-unary-ops': ['error', { | ||
'words': false, | ||
'nonwords': false | ||
}], | ||
'spaced-comment': ['error', 'always'], | ||
@@ -67,2 +83,3 @@ // Ember Suave rules | ||
'ember-suave/no-direct-property-access': 'error', | ||
'ember-suave/prefer-destructuring': 'error', | ||
'ember-suave/require-access-in-comments': 'error', | ||
@@ -69,0 +86,0 @@ 'ember-suave/require-const-for-ember-properties': 'error' |
@@ -12,2 +12,3 @@ /** | ||
var requireIndex = require("requireindex"); | ||
var resolve = require("path").resolve; | ||
@@ -22,4 +23,3 @@ //------------------------------------------------------------------------------ | ||
module.exports.configs = { | ||
recommended: require('../config/recommended') | ||
}; | ||
// import all configurations in ../config | ||
module.exports.configs = requireIndex(resolve(__dirname, "../config")); |
@@ -13,51 +13,50 @@ /** | ||
module.exports = function(context) { | ||
module.exports = { | ||
meta: { | ||
schema: [], | ||
message: MESSAGE | ||
}, | ||
create: function(context) { | ||
// variables should be defined here | ||
// variables should be defined here | ||
//-------------------------------------------------------------------------- | ||
// Helpers | ||
//-------------------------------------------------------------------------- | ||
//-------------------------------------------------------------------------- | ||
// Helpers | ||
//-------------------------------------------------------------------------- | ||
// declaration is a `export const foo = 'asdf'` in root of the module | ||
function isModuleExport(node) { | ||
return node.parent.type === 'ExportNamedDeclaration' && isAtRoot(node.parent); | ||
} | ||
// declaration is in root of module | ||
function isAtRoot(node) { | ||
return node.parent.type === 'Program'; | ||
} | ||
function checkNode(node) { | ||
if (isAtRoot(node)) { | ||
return; | ||
// declaration is a `export const foo = 'asdf'` in root of the module | ||
function isModuleExport(node) { | ||
return node.parent.type === 'ExportNamedDeclaration' && isAtRoot(node.parent); | ||
} | ||
if (isModuleExport(node)) { | ||
return; | ||
// declaration is in root of module | ||
function isAtRoot(node) { | ||
return node.parent.type === 'Program'; | ||
} | ||
if (node.kind === 'const') { | ||
context.report({ | ||
node: node, | ||
message: MESSAGE | ||
}); | ||
function checkNode(node) { | ||
if (isAtRoot(node)) { | ||
return; | ||
} | ||
if (isModuleExport(node)) { | ||
return; | ||
} | ||
if (node.kind === 'const') { | ||
context.report({ | ||
node: node, | ||
message: MESSAGE | ||
}); | ||
} | ||
} | ||
} | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
return { | ||
VariableDeclaration: checkNode | ||
}; | ||
return { | ||
VariableDeclaration: checkNode | ||
}; | ||
} | ||
}; | ||
module.exports.schema = [ | ||
// fill in your schema | ||
]; | ||
module.exports.message = MESSAGE; |
@@ -11,48 +11,51 @@ /** | ||
module.exports = function(context) { | ||
module.exports = { | ||
meta: { | ||
schema: [ | ||
{ | ||
type: 'array', | ||
items: { | ||
type: 'string' | ||
} | ||
} | ||
] | ||
}, | ||
create: function(context) { | ||
var protectedVariables = context.options[0]; | ||
if (!Boolean(protectedVariables) || protectedVariables.length == 0) { | ||
protectedVariables = ["Ember", "DS"]; | ||
} | ||
var protectedVariables = context.options[0]; | ||
if (!Boolean(protectedVariables) || protectedVariables.length == 0) { | ||
protectedVariables = ["Ember", "DS"]; | ||
} | ||
//-------------------------------------------------------------------------- | ||
// Helpers | ||
//-------------------------------------------------------------------------- | ||
//-------------------------------------------------------------------------- | ||
// Helpers | ||
//-------------------------------------------------------------------------- | ||
function objectIsProtected(item) { | ||
return protectedVariables.indexOf(item) >= 0; | ||
} | ||
function objectIsProtected(item) { | ||
return protectedVariables.indexOf(item) >= 0; | ||
} | ||
function assigningToMemberExpression(node) { | ||
return (node.parent.type === 'AssignmentExpression' && node.parent.left === node); | ||
} | ||
function assigningToMemberExpression(node) { | ||
return (node.parent.type === 'AssignmentExpression' && node.parent.left === node); | ||
} | ||
function checkMemberExpression(node) { | ||
var objectName = node.object.name; | ||
function checkMemberExpression(node) { | ||
var objectName = node.object.name; | ||
if (objectIsProtected(objectName) && !assigningToMemberExpression(node)) { | ||
var propertyName = node.property.name; | ||
var message = 'Avoid accessing ' + objectName + '.' + propertyName + ' directly'; | ||
if (objectIsProtected(objectName) && !assigningToMemberExpression(node)) { | ||
var propertyName = node.property.name; | ||
var message = 'Avoid accessing ' + objectName + '.' + propertyName + ' directly'; | ||
context.report({ node: node, message: message }); | ||
context.report({ node: node, message: message }); | ||
} | ||
} | ||
} | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
return { | ||
MemberExpression: checkMemberExpression | ||
}; | ||
return { | ||
MemberExpression: checkMemberExpression | ||
}; | ||
} | ||
}; | ||
module.exports.schema = [ | ||
{ | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
]; |
@@ -14,41 +14,40 @@ /** | ||
module.exports = function(context) { | ||
module.exports = { | ||
meta: { | ||
message: MESSAGE, | ||
schema: [] | ||
}, | ||
create: function(context) { | ||
// variables should be defined here | ||
// variables should be defined here | ||
//-------------------------------------------------------------------------- | ||
// Helpers | ||
//-------------------------------------------------------------------------- | ||
//-------------------------------------------------------------------------- | ||
// Helpers | ||
//-------------------------------------------------------------------------- | ||
function isDocComment(comment) { | ||
return comment.value[0] === '*'; | ||
} | ||
function isDocComment(comment) { | ||
return comment.value[0] === '*'; | ||
} | ||
function includesAccessDeclaration(comment) { | ||
return comment.value.match(/\n(\s*\*\s+|\s*)(@private|@public|@protected)\s/); | ||
} | ||
function includesAccessDeclaration(comment) { | ||
return comment.value.match(/\n(\s*\*\s+|\s*)(@private|@public|@protected)\s/); | ||
} | ||
function checkNode(node) { | ||
if (isDocComment(node) && !includesAccessDeclaration(node)) { | ||
context.report({ | ||
node: node, | ||
message: MESSAGE | ||
}); | ||
function checkNode(node) { | ||
if (isDocComment(node) && !includesAccessDeclaration(node)) { | ||
context.report({ | ||
node: node, | ||
message: MESSAGE | ||
}); | ||
} | ||
} | ||
} | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
return { | ||
BlockComment: checkNode | ||
}; | ||
return { | ||
BlockComment: checkNode | ||
}; | ||
} | ||
}; | ||
module.exports.schema = [ | ||
// fill in your schema | ||
]; | ||
module.exports.message = MESSAGE; |
@@ -13,55 +13,55 @@ /** | ||
module.exports = function(context) { | ||
module.exports = { | ||
meta: { | ||
schema: [] | ||
}, | ||
create: function(context) { | ||
// variables should be defined here | ||
// variables should be defined here | ||
//-------------------------------------------------------------------------- | ||
// Helpers | ||
//-------------------------------------------------------------------------- | ||
//-------------------------------------------------------------------------- | ||
// Helpers | ||
//-------------------------------------------------------------------------- | ||
function checkVariableDeclaration(node) { | ||
var declaration = node.declarations[0]; | ||
function checkVariableDeclaration(node) { | ||
var declaration = node.declarations[0]; | ||
if (hasEmberIdentifier(declaration) && node.kind !== 'const') { | ||
context.report({ node: node, message: MESSAGE }); | ||
if (hasEmberIdentifier(declaration) && node.kind !== 'const') { | ||
context.report({ node: node, message: MESSAGE }); | ||
} | ||
} | ||
} | ||
/** | ||
* Check whether the variables is being created from the Ember global | ||
*/ | ||
function hasEmberIdentifier(declaration) { | ||
var init = declaration.init; | ||
/** | ||
* Check whether the variables is being created from the Ember global | ||
*/ | ||
function hasEmberIdentifier(declaration) { | ||
var init = declaration.init; | ||
if (!Boolean(init)) { | ||
return false; | ||
} | ||
if (!Boolean(init)) { | ||
return false; | ||
} | ||
if (init.type === 'Identifier' && identifierIsEmber(init)) { | ||
return true; | ||
} | ||
if (init.type === 'Identifier' && identifierIsEmber(init)) { | ||
return true; | ||
} | ||
if (init.type === 'MemberExpression') { | ||
var obj = init.object; | ||
if (init.type === 'MemberExpression') { | ||
var obj = init.object; | ||
return identifierIsEmber(obj); | ||
return identifierIsEmber(obj); | ||
} | ||
} | ||
} | ||
function identifierIsEmber(id) { | ||
return id.name === 'Ember'; | ||
} | ||
function identifierIsEmber(id) { | ||
return id.name === 'Ember'; | ||
} | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
return { | ||
VariableDeclaration: checkVariableDeclaration | ||
}; | ||
return { | ||
VariableDeclaration: checkVariableDeclaration | ||
}; | ||
} | ||
}; | ||
module.exports.schema = [ | ||
// fill in your schema | ||
]; |
{ | ||
"name": "eslint-plugin-ember-suave", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Make your Ember App Stylish", | ||
@@ -10,13 +10,26 @@ "keywords": [ | ||
], | ||
"author": "Alex LaFroscia", | ||
"author": "DockYard <oss@dockyard.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Alex LaFroscia" | ||
}, | ||
{ | ||
"name": "Robert Wagner", | ||
"email": "rwwagner90@gmail.com", | ||
"url": "https://github.com/rwwagner90" | ||
} | ||
], | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "mocha tests --recursive", | ||
"test:debug": "mocha debug tests --recursive" | ||
"test": "mocha tests tests/lib/rules/*.js tests/config/*.js" | ||
}, | ||
"dependencies": { | ||
"babel-eslint": "^6.1.2", | ||
"requireindex": "~1.1.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "~2.6.0" | ||
"chai": "^3.5.0", | ||
"eslint": "^3.0.0", | ||
"mocha": "^2.5.3" | ||
}, | ||
@@ -23,0 +36,0 @@ "engines": { |
@@ -1,2 +0,2 @@ | ||
# eslint-plugin-ember-suave [](https://travis-ci.org/alexlafroscia/eslint-plugin-ember-suave) | ||
# eslint-plugin-ember-suave [](https://travis-ci.org/DockYard/eslint-plugin-ember-suave) | ||
Make your Ember App Stylish | ||
@@ -29,3 +29,2 @@ | ||
"extends": [ | ||
"./node_modules/ember-cli-eslint/coding-standard/ember-application.js", | ||
"plugin:ember-suave/recommended" | ||
@@ -45,6 +44,7 @@ ] | ||
"rules": { | ||
"ember-suave/no-const-outside-module-scope": ["error"], | ||
"ember-suave/no-direct-property-access": ["error"], | ||
"ember-suave/require-access-in-comments": ["error"], | ||
"ember-suave/require-const-for-ember-properties": ["error"] | ||
"ember-suave/no-const-outside-module-scope": "error", | ||
"ember-suave/no-direct-property-access": "error", | ||
"ember-suave/prefer-destructuring": "error", | ||
"ember-suave/require-access-in-comments": "error", | ||
"ember-suave/require-const-for-ember-properties": "error" | ||
} | ||
@@ -65,1 +65,22 @@ } | ||
Tests can be run using `npm test`. If you want to debug your rules within Mocha, you can use `npm run test:debug` to step inside your tests. Additionally, [AST Explorer](https://astexplorer.net/) is a great way to look into the structure of a node to determine what to expect. | ||
## Authors | ||
* [Alex LaFroscia](https://github.com/alexlafroscia) | ||
* [Estelle DeBlois](https://github.com/brzpegasus) | ||
## Contributors | ||
* [Robert Wagner](https://github.com/rwwagner90) | ||
## Versioning | ||
This library follows [Semantic Versioning](http://semver.org) | ||
## Legal | ||
[DockYard](http://dockyard.com/), Inc. © 2016 | ||
[@dockyard](http://twitter.com/dockyard) | ||
[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php) |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
16789
37.42%11
10%358
36.12%84
33.33%2
100%3
200%1
Infinity%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added