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

Revamp eslint configuration. #5469

Merged
merged 7 commits into from
May 9, 2018
Merged
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
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tmp
dist
node-tests/fixtures/
blueprints/*/mocha-files/
blueprints/*/qunit-files/
blueprints/*/files/
121 changes: 82 additions & 39 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
/* global module */
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 6,
ecmaVersion: 2017,
sourceType: 'module',
},
extends: 'eslint:recommended',
env: {
'browser': true,
},
globals: {
'heimdall': true,
'Map': false,
},
extends: ['eslint:recommended', 'prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',

'no-unused-vars': ['error', {
'args': 'none',
}],
Expand All @@ -29,35 +24,83 @@ module.exports = {
'no-irregular-whitespace': 'error',
'no-undef': 'error',
'no-eq-null': 'error',
},
overrides: [
// node files
{
files: [
'ember-cli-build.js',
'index.js',
'testem.js',
'lib/**/*.js',
'blueprints/*/index.js',
'blueprints/*.js',
'config/**/*.js',
'tests/dummy/config/**/*.js',
'node-tests/**',
'bin/**',
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
},
env: {
browser: false,
node: true,
es6: true,
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
},

// from JSCS
'array-bracket-spacing': ['error', 'never'],
'comma-style': ['error', 'last'],
'brace-style': ['error', '1tbs', {
'allowSingleLine': true,
}],
'no-spaced-func': 'error',
'no-empty': 'error',
'curly': ['error', 'all'],
'eol-last': 'error',
'no-trailing-spaces': 'error',
'comma-dangle': ['error', 'never'],
'space-before-blocks': ['error', 'always'],
'indent': ['error', 2, {
'SwitchCase': 1,
}],
'keyword-spacing': ['error', {
'overrides': {
'else': {
'before': true,
},
'while': {
'before': true,
},
'catch': {
'before': true,
},
// browser files
{
files: [
'addon/**',
'app/**',
'tests/**',
],
excludedFiles: [
'tests/dummy/config/**'
],
env: {
browser: true,
node: false,
},
}],
},
globals: {
heimdall: true,
Map: false,
}
},

// browser tests
{
files: [
'tests/**'
],

rules: {
'no-console': 0
}
},

// node tests
{
files: [
'node-tests/**'
],

env: {
mocha: true,
}
}
],
};
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ testem.js
*.gemspec
**/*.rb
node-tests/
lib/yuidoc.js
lib/version-replace.js
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
singleQuote: true,
trailingComma: 'es5',
printWidth: 100,
};
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
env: NAME=test # used only to make Travis UI show description
script:
- ./bin/lint-features
- yarn lint:js
- yarn test

- stage: additional tests
Expand Down
9 changes: 7 additions & 2 deletions addon/-debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ if (DEBUG) {
return modelClass.detect(addedModelClass);
};

assertPolymorphicType = function assertPolymorphicType(parentInternalModel, relationshipMeta, addedInternalModel, store) {
assertPolymorphicType = function assertPolymorphicType(
parentInternalModel,
relationshipMeta,
addedInternalModel,
store
) {
let addedModelName = addedInternalModel.modelName;
let parentModelName = parentInternalModel.modelName;
let key = relationshipMeta.key;
Expand All @@ -53,4 +58,4 @@ if (DEBUG) {
};
}

export { assertPolymorphicType }
export { assertPolymorphicType };
26 changes: 18 additions & 8 deletions addon/-private/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ export default Mixin.create({

if (modelName) {
path = this.pathForType(modelName);
if (path) { url.push(path); }
if (path) {
url.push(path);
}
}

if (id) { url.push(encodeURIComponent(id)); }
if (prefix) { url.unshift(prefix); }
if (id) {
url.push(encodeURIComponent(id));
}
if (prefix) {
url.unshift(prefix);
}

url = url.join('/');
if (!host && url && url.charAt(0) !== '/') {
Expand Down Expand Up @@ -392,19 +398,23 @@ export default Mixin.create({
// Do nothing, the full host is already included.
return path;

// Absolute path
// Absolute path
} else if (path.charAt(0) === '/') {
return `${host}${path}`;
// Relative path
// Relative path
} else {
return `${parentURL}/${path}`;
}
}

// No path provided
let url = [];
if (host) { url.push(host); }
if (namespace) { url.push(namespace); }
if (host) {
url.push(host);
}
if (namespace) {
url.push(namespace);
}
return url.join('/');
},

Expand Down Expand Up @@ -439,5 +449,5 @@ export default Mixin.create({
pathForType(modelName) {
let camelized = camelize(modelName);
return pluralize(camelized);
}
},
});
29 changes: 16 additions & 13 deletions addon/-private/adapters/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export function AdapterError(errors, message = 'Adapter operation failed') {
this.errors = errors || [
{
title: 'Adapter Error',
detail: message
}
detail: message,
},
];
}

Expand Down Expand Up @@ -165,8 +165,10 @@ AdapterError.extend = extendFn(AdapterError);
@class InvalidError
@namespace DS
*/
export const InvalidError = extend(AdapterError,
'The adapter rejected the commit because it was invalid');
export const InvalidError = extend(
AdapterError,
'The adapter rejected the commit because it was invalid'
);

/**
A `DS.TimeoutError` is used by an adapter to signal that a request
Expand Down Expand Up @@ -200,8 +202,7 @@ export const InvalidError = extend(AdapterError,
@class TimeoutError
@namespace DS
*/
export const TimeoutError = extend(AdapterError,
'The adapter operation timed out');
export const TimeoutError = extend(AdapterError, 'The adapter operation timed out');

/**
A `DS.AbortError` is used by an adapter to signal that a request to
Expand All @@ -212,8 +213,7 @@ export const TimeoutError = extend(AdapterError,
@class AbortError
@namespace DS
*/
export const AbortError = extend(AdapterError,
'The adapter operation was aborted');
export const AbortError = extend(AdapterError, 'The adapter operation was aborted');

/**
A `DS.UnauthorizedError` equates to a HTTP `401 Unauthorized` response
Expand Down Expand Up @@ -320,7 +320,10 @@ export const ConflictError = extend(AdapterError, 'The adapter operation failed
@class ServerError
@namespace DS
*/
export const ServerError = extend(AdapterError, 'The adapter operation failed due to a server error');
export const ServerError = extend(
AdapterError,
'The adapter operation failed due to a server error'
);

/**
Convert an hash of errors into an array with errors in JSON-API format.
Expand Down Expand Up @@ -372,7 +375,7 @@ export function errorsHashToArray(errors) {
let out = [];

if (isPresent(errors)) {
Object.keys(errors).forEach((key) => {
Object.keys(errors).forEach(key => {
let messages = makeArray(errors[key]);
for (let i = 0; i < messages.length; i++) {
let title = 'Invalid Attribute';
Expand All @@ -385,8 +388,8 @@ export function errorsHashToArray(errors) {
title: title,
detail: messages[i],
source: {
pointer: pointer
}
pointer: pointer,
},
});
}
});
Expand Down Expand Up @@ -439,7 +442,7 @@ export function errorsArrayToHash(errors) {
let out = {};

if (isPresent(errors)) {
errors.forEach((error) => {
errors.forEach(error => {
if (error.source && error.source.pointer) {
let key = error.source.pointer.match(SOURCE_POINTER_REGEXP);

Expand Down
14 changes: 7 additions & 7 deletions addon/-private/attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ function getDefaultValue(record, options, key) {
return options.defaultValue.apply(null, arguments);
} else {
let defaultValue = options.defaultValue;
assert(`Non primitive defaultValues are not supported because they are shared between all instances. If you would like to use a complex object as a default value please provide a function that returns the complex object.`,
typeof defaultValue !== 'object' || defaultValue === null);
assert(
`Non primitive defaultValues are not supported because they are shared between all instances. If you would like to use a complex object as a default value please provide a function that returns the complex object.`,
typeof defaultValue !== 'object' || defaultValue === null
);
return defaultValue;
}
}

function hasValue(record, key) {
return key in record._attributes ||
key in record._inFlightAttributes ||
key in record._data;
return key in record._attributes || key in record._inFlightAttributes || key in record._data;
}

/**
Expand Down Expand Up @@ -118,7 +118,7 @@ export default function attr(type, options) {
let meta = {
type: type,
isAttribute: true,
options: options
options: options,
};

return computed({
Expand All @@ -132,6 +132,6 @@ export default function attr(type, options) {
},
set(key, value) {
return this._internalModel.setDirtyAttribute(key, value);
}
},
}).meta(meta);
}
2 changes: 1 addition & 1 deletion addon/-private/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import VERSION from 'ember-data/version';
*/
const DS = Ember.Namespace.create({
VERSION: VERSION,
name: "DS"
name: 'DS',
});

if (Ember.libraries) {
Expand Down
Loading