Skip to content

Commit

Permalink
Update ESLint config incl. Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Jun 20, 2019
1 parent 105e3bb commit 4d80acc
Show file tree
Hide file tree
Showing 105 changed files with 3,116 additions and 2,288 deletions.
71 changes: 60 additions & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
'use strict';

module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
},
plugins: ['import', 'prettier'],
extends: ['eslint:recommended', 'plugin:import/errors', 'plugin:import/warnings', 'prettier'],
env: {
node: true,
jest: true,
},
extends: [
'airbnb-base',
],
rules: {
'func-names': 0,
'no-use-before-define': 0,
'no-plusplus': 0,
'strict': 0,
'comma-dangle': [0, {
'functions': 'never',
}],
// Possible Errors
// 'no-async-promise-executor': 'error', // available in ESLint 5
'no-template-curly-in-string': 'error',
// 'require-atomic-updates': 'error', // available in ESLint 5

// Best Practices
'array-callback-return': 'error',
eqeqeq: 'error',
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-implicit-coercion': 'error',
'no-implied-eval': 'error',
'no-lone-blocks': 'error',
'no-new-func': 'error',
'no-new-wrappers': 'error',
'no-octal-escape': 'error',
'no-return-assign': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-throw-literal': 'error',
'no-unused-expressions': 'error',
'no-useless-call': 'error',
// 'no-useless-catch': 'error', // available in ESLint 5
'no-useless-concat': 'error',
'no-useless-escape': 'error',
'no-useless-return': 'error',
'no-void': 'error',
'no-with': 'error',
'prefer-promise-reject-errors': 'error',
radix: 'error',
'wrap-iife': 'error',
yoda: 'error',

// ECMAScript 6
'no-duplicate-imports': 'error',
'no-useless-computed-key': 'error',
'no-useless-constructor': 'error',
'no-useless-rename': 'error',
'no-var': 'error',
'object-shorthand': 'error',
'prefer-numeric-literals': 'error',

'prettier/prettier': 'error',
},
}
overrides: [
// test files
{
files: ['tests/**/*.js',],
env: { jest: true },
},
],
};
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ logs
node_modules

# Misc
.eslintcache
coverage
npm-debug.log
*.swp
.vscode
.vscode
8 changes: 8 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
printWidth: 100,
semi: true,
singleQuote: true,
trailingComma: 'es5',
};
6 changes: 2 additions & 4 deletions lib/config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ module.exports = {

parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
sourceType: 'module',
},

env: {
browser: true,
es6: true,
},

plugins: [
'ember',
],
plugins: ['ember'],
};
15 changes: 6 additions & 9 deletions lib/rules/alias-model-in-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ module.exports = {
description: 'Enforces aliasing model in controller',
category: 'Best Practices',
recommended: false,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/alias-model-in-controller.md'
url:
'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/alias-model-in-controller.md',
},
fixable: null, // or "code" or "whitespace"
},

create(context) {
const message = 'Alias your model';

const report = function (node) {
const report = function(node) {
context.report(node, message);
};

Expand All @@ -34,27 +35,23 @@ module.exports = {
const properties = ember.getModuleProperties(node);
let aliasPresent = false;

properties.forEach((property) => {
properties.forEach(property => {
const parsedCallee = utils.parseCallee(property.value);
const parsedArgs = utils.parseArgs(property.value);

if (
parsedCallee.length &&
['alias', 'readOnly', 'reads'].indexOf(parsedCallee.pop()) > -1 &&
(
parsedArgs[0] === 'model' ||
String(parsedArgs[0]).startsWith('model.')
)
(parsedArgs[0] === 'model' || String(parsedArgs[0]).startsWith('model.'))
) {
aliasPresent = true;
}
});


if (!aliasPresent) {
report(node);
}
},
};
}
},
};
17 changes: 10 additions & 7 deletions lib/rules/avoid-leaking-state-in-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ module.exports = {
category: 'Possible Errors',
recommended: false,
replacedBy: ['avoid-leaking-state-in-ember-objects'],
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/avoid-leaking-state-in-components.md'
url:
'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/avoid-leaking-state-in-components.md',
},
fixable: null, // or "code" or "whitespace"
deprecated: true,
schema: [{
type: 'array',
items: { type: 'string' },
}],
schema: [
{
type: 'array',
items: { type: 'string' },
},
],
},

create(context) {
Expand All @@ -32,7 +35,7 @@ module.exports = {
object: 'Avoid using objects as default properties',
};

const report = function (node, messageType) {
const report = function(node, messageType) {
context.report(node, message[messageType]);
};

Expand All @@ -56,7 +59,7 @@ module.exports = {

properties
.filter(property => ignoredProperties.indexOf(property.key.name) === -1)
.forEach((property) => {
.forEach(property => {
if (ember.isObjectProp(property)) {
report(property, 'object');
} else if (ember.isArrayProp(property)) {
Expand Down
33 changes: 18 additions & 15 deletions lib/rules/avoid-leaking-state-in-ember-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ const DEFAULT_IGNORED_PROPERTIES = [
'attrs',
];

const isAllowed = function (property) {
const isAllowed = function(property) {
const value = property.value;
return ember.isFunctionExpression(value) ||
return (
ember.isFunctionExpression(value) ||
utils.isLiteral(value) ||
utils.isIdentifier(value) ||
utils.isCallExpression(value) ||
utils.isBinaryExpression(value) ||
utils.isTemplateLiteral(value) ||
utils.isTaggedTemplateExpression(value) ||
utils.isMemberExpression(value) ||
utils.isUnaryExpression(value);
utils.isUnaryExpression(value)
);
};


//------------------------------------------------------------------------------
// Ember object rule - Avoid leaking state
// (Don't use arrays or objects as default props)
Expand All @@ -40,22 +41,26 @@ module.exports = {
description: 'Avoids state leakage',
category: 'Ember Object',
recommended: true,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/avoid-leaking-state-in-ember-objects.md'
url:
'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/avoid-leaking-state-in-ember-objects.md',
},
fixable: null, // or "code" or "whitespace"
schema: [{
type: 'array',
items: { type: 'string' },
}],
schema: [
{
type: 'array',
items: { type: 'string' },
},
],
},

DEFAULT_IGNORED_PROPERTIES,

create(context) {
const ignoredProperties = context.options[0] || DEFAULT_IGNORED_PROPERTIES;

const report = function (node) {
const message = 'Only string, number, symbol, boolean, null, undefined, and function are allowed as default properties';
const report = function(node) {
const message =
'Only string, number, symbol, boolean, null, undefined, and function are allowed as default properties';
context.report(node, message);
};

Expand All @@ -66,10 +71,8 @@ module.exports = {
const properties = ember.getModuleProperties(node);

properties
.filter(property =>
property.key && ignoredProperties.indexOf(property.key.name) === -1
)
.forEach((property) => {
.filter(property => property.key && ignoredProperties.indexOf(property.key.name) === -1)
.forEach(property => {
if (!isAllowed(property)) {
report(property);
}
Expand Down
9 changes: 5 additions & 4 deletions lib/rules/avoid-using-needs-in-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ module.exports = {
docs: {
description: 'Avoids using needs in controllers',
category: 'Best Practices',
recommended: true
recommended: true,
},
fixable: null, // or "code" or "whitespace"
},

create(context) {
const report = function (node) {
const message = '`needs` API has been deprecated, `Ember.inject.controller` should be used instead';
const report = function(node) {
const message =
'`needs` API has been deprecated, `Ember.inject.controller` should be used instead';
context.report(node, message);
};
const filePath = context.getFilename();
Expand All @@ -31,7 +32,7 @@ module.exports = {

const properties = ember.getModuleProperties(node);

properties.forEach((property) => {
properties.forEach(property => {
if (property.key.name === 'needs') {
report(property);
}
Expand Down
10 changes: 6 additions & 4 deletions lib/rules/closure-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ module.exports = {
description: 'Enforces usage of closure actions',
category: 'Best Practices',
recommended: true,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/closure-actions.md'
url:
'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/closure-actions.md',
},
fixable: null, // or "code" or "whitespace"
},

ERROR_MESSAGE,

create(context) {
const report = function (node) {
const report = function(node) {
context.report(node, ERROR_MESSAGE);
};

return {
MemberExpression(node) {
const isSendAction = utils.isThisExpression(node.object) &&
const isSendAction =
utils.isThisExpression(node.object) &&
utils.isIdentifier(node.property) &&
node.property.name === 'sendAction';

Expand All @@ -37,5 +39,5 @@ module.exports = {
}
},
};
}
},
};
Loading

0 comments on commit 4d80acc

Please sign in to comment.