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 18, 2018
1 parent db9455b commit 303c23e
Show file tree
Hide file tree
Showing 14 changed files with 590 additions and 420 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,
]);
24 changes: 13 additions & 11 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,17 +37,17 @@ const browserLaunchers = {
'IE': 'karma-ie-launcher',
'Opera': 'karma-opera-launcher',
'PhantomJS': 'karma-phantomjs-launcher',
'Safari': 'karma-safari-launcher'
'Safari': 'karma-safari-launcher',
};

const merge = (arr1 = [], arr2 = []) => common.merge(arr1, arr2);

const exclude = (files, filterArr) =>
filterArr.map(path => path.replace('.', '\\.')
const exclude = (files, filterArr) => filterArr.map(
path => path.replace('.', '\\.')
.replace('*', '.+')
.replace('?', '.'))
.map(path => new RegExp(path))
.reduce((files, regexp) => files.filter(file => !regexp.test(file)), files);
.map(path => new RegExp(path))
.reduce((files, regexp) => files.filter(file => !regexp.test(file)), files);

const parseFile = file => {
const data = fs.readFileSync(path.resolve(file), 'utf8');
Expand All @@ -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 @@ -133,20 +134,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 +169,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
2 changes: 1 addition & 1 deletion lib/declarative-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class DeclarativeTest extends Test {
actual: sResult,
expected: sExpected,
message: msg,
stack: new Error().stack
stack: new Error().stack,
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/imperative-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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 +66,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 +132,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 +231,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 @@ -389,7 +389,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
2 changes: 1 addition & 1 deletion lib/report.js
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Runner extends EventEmitter {
this.reporter = new ConciseReporter();
this.hasFailures = false;
this.testsCount = 0;
this._testDoneCallback = (test) => {
this._testDoneCallback = test => {
if (!test.success) this.hasFailures = true;
if (this.reporter) this.reporter.record(test);
if (--this.testsCount === 0) {
Expand Down
6 changes: 3 additions & 3 deletions lib/speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const speed = (
count,
tests
) => {
const times = tests.map((fn) => {
const times = tests.map(fn => {
const result = [];
const begin = process.hrtime();
for (let i = 0; i < count; i++) result.push(fn());
Expand All @@ -19,8 +19,8 @@ const speed = (
});
const top = times.sort((t1, t2) => (t1.time - t2.time));
const best = top[0].time;
const relative = (time) => (time * 100 / best);
top.forEach((test) => {
const relative = time => (time * 100 / best);
top.forEach(test => {
test.percent = Math.round(
Math.round(relative(test.time) * 100) / 100
) - 100;
Expand Down
2 changes: 1 addition & 1 deletion metatests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const metatests = {
ImperativeTest,
test,
testSync,
testAsync
testAsync,
};

if (process.browser) {
Expand Down
Loading

0 comments on commit 303c23e

Please sign in to comment.