Skip to content

Commit

Permalink
Use eslint-config-metarhia and fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
belochub committed Oct 29, 2018
1 parent 5267851 commit 61e3d94
Show file tree
Hide file tree
Showing 14 changed files with 527 additions and 462 deletions.
174 changes: 1 addition & 173 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,173 +1 @@
env:
es6: true
node: true
extends: 'eslint:recommended'
globals:
metatests: false
rules:
indent:
- error
- 2
- SwitchCase: 1
VariableDeclarator:
var: 2
let: 2
const: 3
MemberExpression: 1
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- always
eqeqeq:
- error
- always
no-loop-func:
- error
strict:
- error
- global
block-spacing:
- error
- always
brace-style:
- error
- 1tbs
- allowSingleLine: true
camelcase:
- error
comma-style:
- error
- last
comma-spacing:
- error
- before: false
after: true
eol-last:
- error
func-call-spacing:
- error
- never
key-spacing:
- error
- beforeColon: false
afterColon: true
mode: minimum
keyword-spacing:
- error
- before: true
after: true
overrides:
function:
after: false
max-len:
- error
- code: 80
ignoreUrls: true
max-nested-callbacks:
- error
- max: 7
new-cap:
- error
- newIsCap: true
capIsNew: true
properties: true
new-parens:
- error
no-lonely-if:
- error
no-trailing-spaces:
- error
no-unneeded-ternary:
- error
no-whitespace-before-property:
- error
object-curly-spacing:
- error
- always
operator-assignment:
- error
- always
operator-linebreak:
- error
- after
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: true
nonwords: false
overrides:
typeof: false
no-unreachable:
- error
no-global-assign:
- error
no-self-compare:
- error
no-unmodified-loop-condition:
- error
no-constant-condition:
- error
- checkLoops: false
no-console:
- off
no-useless-concat:
- error
no-useless-escape:
- error
no-shadow-restricted-names:
- error
no-use-before-define:
- error
- functions: false
arrow-body-style:
- error
- as-needed
arrow-spacing:
- error
no-confusing-arrow:
- error
- allowParens: true
no-useless-computed-key:
- error
no-useless-rename:
- error
no-var:
- error
object-shorthand:
- error
- always
prefer-arrow-callback:
- error
prefer-const:
- error
prefer-numeric-literals:
- error
prefer-rest-params:
- error
prefer-spread:
- error
rest-spread-spacing:
- error
- never
template-curly-spacing:
- error
- never
extends: 'metarhia'
4 changes: 2 additions & 2 deletions benchmarks/speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const defineArrayOfNumber = () => [100500, 100500, 100500];
const defineObject = () => ({
hello: 'world',
size: 100500,
flag: true
flag: true,
});

const mixinObject = () => {
Expand Down Expand Up @@ -77,5 +77,5 @@ metatests.speed('Benchmark example', 2000000, [
newClass,
newObject,
objectCreate,
callFactory
callFactory,
]);
20 changes: 12 additions & 8 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const cliOptions = [
[ '--browsers <values>', 'Browsers to run', splitOpts, [] ],
[ '-l, --browser-log <value>', 'Browser log level' ],
[ '-p, --browser-port <n>', 'Browser port' ],
[ '-c, --config <value>', 'Config file' ]
[ '-c, --config <value>', 'Config file' ],
];

const karmaLogLevels = {
'disable': [ 'LOG_DISABLE', 'none' ],
'error': [ 'LOG_ERROR', 'errors-only' ],
'warn': [ 'LOG_WARN', 'minimal' ],
'info': [ 'LOG_INFO', 'normal' ],
'debug': [ 'LOG_DEBUG', 'verbose' ]
'debug': [ 'LOG_DEBUG', 'verbose' ],
};

const browserLaunchers = {
Expand All @@ -37,7 +37,7 @@ const browserLaunchers = {
'Firefox': 'karma-firefox-launcher',
'IE': 'karma-ie-launcher',
'Opera': 'karma-opera-launcher',
'Safari': 'karma-safari-launcher'
'Safari': 'karma-safari-launcher',
};

const merge = (arr1 = [], arr2 = []) => common.merge(arr1, arr2);
Expand Down Expand Up @@ -73,6 +73,7 @@ const loadFiles = files => {
} else {
console.error('File does not exist:', file);
process.exit(1);
return '';
}
})
.forEach(file => {
Expand Down Expand Up @@ -111,7 +112,9 @@ const setKarmaLogLevel = (config, logLevel = 'disable') => {
const removeNodePackages = (config, ...packages) => {
if (!config.webpack) config.webpack = {};
if (!config.webpack.node) config.webpack.node = {};
packages.forEach(lib => config.webpack.node[lib] = 'empty');
packages.forEach(lib => {
config.webpack.node[lib] = 'empty';
});
};

const getReporter = () => {
Expand All @@ -133,20 +136,20 @@ const getReporter = () => {
return reporter;
};

const getBrowserConfig = (conf) => {
const getBrowserConfig = conf => {
const config = {
preprocessors: {},
files: [],
plugins: [
'karma-webpack',
{ 'reporter:meta': ['type', getReporter()] }
{ 'reporter:meta': ['type', getReporter()] },
],
reporters: [ 'meta' ],
basePath: process.env.PWD,
port: conf.browser.port,
autoWatch: false,
singleRun: true,
concurrency: 1
concurrency: 1,
};

const adapter = path.resolve('./build/adapter.js');
Expand All @@ -168,8 +171,9 @@ const getEnvironment = (config, program) => {
if (program.browser) config.environments.push('browser');
return;
}
if (!config.environments || config.environments.length === 0)
if (!config.environments || config.environments.length === 0) {
config.environments = [ 'node' ];
}
config.environments = Array.from(new Set(config.environments));

const environments = ['node', 'browser'];
Expand Down
8 changes: 5 additions & 3 deletions lib/declarative-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class DeclarativeTest extends Test {

Object.keys(defaultOptions)
.filter(k => this.options[k] === undefined)
.forEach(k => this.options[k] = defaultOptions[k]);
.forEach(k => {
this.options[k] = defaultOptions[k];
});

if (this.options.run) this.run();
}
Expand Down Expand Up @@ -97,7 +99,7 @@ class DeclarativeTest extends Test {

const success = expectedType === 'function' ?
expected(result) :
(sResult === sExpected);
sResult === sExpected;

this.results.push({
success,
Expand All @@ -106,7 +108,7 @@ class DeclarativeTest extends Test {
actual: sResult,
expected: sExpected,
message: msg,
stack: new Error().stack
stack: new Error().stack,
});
}
}
Expand Down
18 changes: 11 additions & 7 deletions lib/imperative-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class ImperativeTest extends Test {

Object.keys(defaultTestOptions)
.filter(k => this.options[k] === undefined)
.forEach(k => this.options[k] = defaultTestOptions[k]);
.forEach(k => {
this.options[k] = defaultTestOptions[k];
});

this.subtestId = 0;
this.subtests = new Map();
Expand All @@ -44,7 +46,7 @@ class ImperativeTest extends Test {
}

_setupSubtestCallbacks() {
const subtestCallbackEnd = (test) => {
const subtestCallbackEnd = test => {
if (this.subtestQueue.length > 0 && test.id === this.subtestQueue[0].id) {
this.subtestQueue.shift();
if (this.subtestQueue.length > 0) {
Expand All @@ -66,7 +68,7 @@ class ImperativeTest extends Test {
}
};

this._subtestCallback = (test) => {
this._subtestCallback = test => {
this.subtests.delete(test.id);
this.results.push({
type: 'subtest',
Expand Down Expand Up @@ -132,7 +134,7 @@ class ImperativeTest extends Test {
test.on('done', this._subtestCallback);
test.on('error', this._subtestErrorCallback);
if (this.beforeEachFunc) {
this.beforeEachFunc(test, (context) => {
this.beforeEachFunc(test, context => {
Object.assign(test.context, context);
test.run();
});
Expand Down Expand Up @@ -231,7 +233,7 @@ class ImperativeTest extends Test {
error(err, message) {
this._check(
'error',
(err) => !(err instanceof Error),
err => !(err instanceof Error),
err,
null,
message
Expand Down Expand Up @@ -371,7 +373,9 @@ class ImperativeTest extends Test {

function makeAliases(target, aliases) {
Object.keys(aliases).forEach(method => {
aliases[method].forEach(alias => target[alias] = target[method]);
aliases[method].forEach(alias => {
target[alias] = target[method];
});
});
}

Expand All @@ -389,7 +393,7 @@ const test = (
runner = runnerInstance
) => {
if (!runner.options.runTodo && options.todo) {
return;
return null;
}
const test = new ImperativeTest(caption, func, options);
runner.addTest(test);
Expand Down
8 changes: 4 additions & 4 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ const { capitalize } = require('metarhia-common');

const LINE_LENGTH = 12;

const lpad = (s, count, char = ' ') => (char.repeat(count - s.length) + s);
const lpad = (s, count, char = ' ') => char.repeat(count - s.length) + s;

const line = (title, s) => `\n${lpad(title, LINE_LENGTH)}: ${s}`;

const renderStack = stack => {
const path = process.cwd();
const lines = stack.split('\n');
lines.splice(1, 1);
const result = lines.map((line, i) => (
const result = lines.map((line, i) =>
' '.repeat(i ? 12 : 0) +
line.trim().replace(/at /g, '').replace(path, '')
)).filter(line => !line.includes('(internal/'));
).filter(line => !line.includes('(internal/'));
return result.join('\n');
};

Expand Down Expand Up @@ -68,7 +68,7 @@ class ConciseReporter extends Reporter {
if (test.metadata.filename) message += ` ${test.metadata.filename}`;

let firstFailure = true;
test.results.forEach((res) => {
test.results.forEach(res => {
if (res.type === 'subtest') {
const t = res.test;
if (!t.success) {
Expand Down
Loading

0 comments on commit 61e3d94

Please sign in to comment.