Skip to content

Commit

Permalink
lint: Add lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed May 31, 2020
1 parent 72decaf commit ce5edda
Show file tree
Hide file tree
Showing 25 changed files with 96 additions and 85 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.js
Expand Up @@ -64,6 +64,20 @@ module.exports = {
skipWords,
},
],
'no-lonely-if': 2,
'sort-keys': [
1,
'asc',
{
natural: true,
minKeys: 4,
},
],
'no-unneeded-ternary': 2,
'no-unused-expressions': 2,
'no-useless-catch': 2,
'no-duplicate-imports': 2,
'max-params': [2, { max: 3 }],
},
ignorePatterns: ['dist', 'node_modules', 'playground'],
};
4 changes: 2 additions & 2 deletions config/index.js
Expand Up @@ -6,8 +6,8 @@ const PACKAGES_PATH = path.resolve(ROOT_PATH, 'packages');
const BABEL_CONFIG_PATH = path.resolve(CONFIG_PATH, 'babel', 'babel.config.js');

module.exports = {
ROOT_PATH,
BABEL_CONFIG_PATH,
CONFIG_PATH,
PACKAGES_PATH,
BABEL_CONFIG_PATH,
ROOT_PATH,
};
9 changes: 5 additions & 4 deletions docs/group.md
Expand Up @@ -7,7 +7,7 @@ Similar to the `describe` and `context` features provided by unit testing framew
import vest, { test, group, enforce } from 'vest';

vest.create('authentication_form', data => {
vest.skip(data.userExists ? 'newUser' : 'existingUser');
vest.skip(data.userExists ? 'signUp' : 'signIn');

test('userName', "Can't be empty", () => {
enforce(data.username).isNotEmpty();
Expand All @@ -16,14 +16,15 @@ vest.create('authentication_form', data => {
enforce(data.password).isNotEmpty();
});

group('existingUser', () => {
group('signIn', () => {
test(
'userName',
'User does not exist. Please check if you typed it correctly.'
'User not found. Please check if you typed it correctly.',
findUserName(data.username)
);
});

group('newUser', () => {
group('signUp', () => {
test('email', 'Email already registered', isEmailRegistered(data.email));

test('age', 'You must be at least 18 years old to join', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin-vest/lib/constants/index.js
@@ -1,10 +1,10 @@
const constants = {
VEST_HOOK_WARN: 'warn',
VEST_HOOK_DRAFT: 'draft',
VEST_HOOK_ONLY: 'only',
VEST_HOOK_SKIP: 'skip',
VEST_HOOK_DRAFT: 'draft',
VEST_IDENTIFIER_VALIDATE: 'validate',
VEST_HOOK_WARN: 'warn',
VEST_IDENTIFIER_TEST: 'test',
VEST_IDENTIFIER_VALIDATE: 'validate',
VEST_KEYWORD: 'vest',
};

Expand Down
Expand Up @@ -5,11 +5,11 @@ const { isTestCall, looksLikeExclusion, errorMessage } = require('./helpers');
module.exports = {
meta: {
docs: {
type: 'problem',
category: 'Possible Errors',
description:
'Makes sure vest exclusion hooks are not put before your test calls',
category: 'Possible Errors',
recommended: true,
type: 'problem',
},
fixable: 'code',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/core/createSuite/index.js
Expand Up @@ -23,8 +23,8 @@ const createSuite = (name, tests) => {

const ctxRef = singleton.useContext() ?? {
name,
tests,
operationMode: OPERATION_MODE_STATEFUL,
tests,
...(shouldCreateId && {
suiteId: name,
}),
Expand Down
1 change: 1 addition & 0 deletions packages/vest/src/core/produce/getByGroup/index.js
@@ -1,3 +1,4 @@
/* eslint-disable max-params */
import throwError from '../../../lib/throwError';
import collectFailureMessages from '../collectFailureMessages';

Expand Down
1 change: 1 addition & 0 deletions packages/vest/src/core/produce/hasByGroup/index.js
@@ -1,3 +1,4 @@
/* eslint-disable max-params */
import { hasLogic } from '../has';

/**
Expand Down
21 changes: 9 additions & 12 deletions packages/vest/src/core/produce/index.js
Expand Up @@ -100,18 +100,15 @@ const produce = (state, { draft } = {}) =>
],
]
.concat(draft ? [] : [['done', done.bind(null, state)]])
.reduce(
(properties, [name, value]) =>
Object.assign(properties, {
[name]: {
value,
writeable: true,
configurable: true,
enumerable: true,
},
}),
{}
)
.reduce((properties, [name, value]) => {
properties[name] = {
configurable: true,
enumerable: true,
value,
writeable: true,
};
return properties;
}, {})
));

export default produce;
21 changes: 10 additions & 11 deletions packages/vest/src/core/state/registerSuite/index.js
Expand Up @@ -7,16 +7,16 @@ import singleton from '../../../lib/singleton';
* @param {string} name Name of the validation suite.
*/
const INITIAL_SUITE_STATE = (suiteId, name) => ({
name,
suiteId,
pending: [],
lagging: [],
doneCallbacks: [],
exclusive: {},
fieldCallbacks: {},
tests: {},
groups: {},
exclusive: {},
lagging: [],
name,
pending: [],
suiteId,
testObjects: [],
tests: {},
});

/**
Expand Down Expand Up @@ -50,11 +50,10 @@ const registerSuite = () => {

suite.unshift(next);
suite.length = 2;
setSuites(state =>
Object.assign(state, {
[suiteId]: suite,
})
);
setSuites(state => {
state[suiteId] = suite;
return state;
});
};

export default registerSuite;
1 change: 0 additions & 1 deletion packages/vest/src/core/state/reset/spec.js
Expand Up @@ -47,7 +47,6 @@ const spec = _vest => {
});

describe('When suite does not exist in state', () => {
state;
beforeEach(() => {
runRegisterSuite({ name: suiteId, suiteId });
state = copy(getState());
Expand Down
4 changes: 2 additions & 2 deletions packages/vest/src/core/test/index.js
Expand Up @@ -69,10 +69,10 @@ const test = (fieldName, ...args) => {
const ctx = singleton.useContext();

const testObject = new VestTest({
group: ctx.groupName,
suiteId: ctx.suiteId,
fieldName,
group: ctx.groupName,
statement,
suiteId: ctx.suiteId,
testFn,
});

Expand Down
10 changes: 5 additions & 5 deletions packages/vest/src/core/test/lib/VestTest/index.js
Expand Up @@ -10,13 +10,13 @@ import id from '../../../../lib/id';
*/
function VestTest({ suiteId, fieldName, statement, testFn, group }) {
Object.assign(this, {
suiteId,
testFn,
fieldName,
statement,
isWarning: false,
failed: false,
fieldName,
id: id(),
isWarning: false,
statement,
suiteId,
testFn,
});

if (group) {
Expand Down
6 changes: 3 additions & 3 deletions packages/vest/src/core/test/lib/VestTest/spec.js
Expand Up @@ -10,9 +10,9 @@ describe('VestTest', () => {

beforeEach(() => {
testObject = new VestTest({
suiteId,
fieldName,
statement,
suiteId,
testFn: jest.fn(),
});
});
Expand All @@ -24,7 +24,7 @@ describe('VestTest', () => {
it('Should have a unique id', () => {
Array.from(
{ length: 100 },
() => new VestTest({ suiteId, fieldName, statement, testFn: jest.fn() })
() => new VestTest({ fieldName, statement, suiteId, testFn: jest.fn() })
).reduce((existing, { id }) => {
expect(existing[id]).toBeUndefined();
existing[id] = true;
Expand All @@ -51,9 +51,9 @@ describe('VestTest', () => {

const VestTest = require('.');
testObject = new VestTest({
suiteId,
fieldName,
statement,
suiteId,
testFn: jest.fn(),
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/vest/src/core/test/lib/canceled/index.js
Expand Up @@ -12,10 +12,10 @@ export const setCanceled = (...testObjects) => {

setState(state => ({
...state,
[SYMBOL_CANCELED]: testObjects.reduce(
(ids, testObjects) => Object.assign(ids, { [testObjects.id]: true }),
state[SYMBOL_CANCELED]
),
[SYMBOL_CANCELED]: testObjects.reduce((ids, testObjects) => {
ids[testObjects.id] = true;
return ids;
}, state[SYMBOL_CANCELED]),
}));
};

Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/core/test/lib/canceled/spec.js
Expand Up @@ -9,9 +9,9 @@ const genTests = () =>
{ length: 5 },
(_, i) =>
new VestTest({
suite_id: 'suite_id',
fieldName: `field_${i}`,
statement: 'msg',
suite_id: 'suite_id',
testFn: jest.fn(),
})
);
Expand Down
4 changes: 2 additions & 2 deletions packages/vest/src/core/test/lib/pending/spec.js
Expand Up @@ -18,9 +18,9 @@ describe('module: pending', () => {
beforeEach(() => {
state = _.cloneDeep(getSuiteState(suiteId));
testObject = new VestTest({
suiteId,
fieldName: 'field_1',
statement: 'failure_message',
suiteId,
testFn: jest.fn(),
});
});
Expand Down Expand Up @@ -72,9 +72,9 @@ describe('module: pending', () => {
{ length: 5 },
(v, i) =>
new VestTest({
suiteId,
fieldName: `test_${i}`,
statement: 'Some statement string',
suiteId,
testFn: jest.fn(),
})
);
Expand Down
4 changes: 2 additions & 2 deletions packages/vest/src/core/test/runAsyncTest/spec.js
Expand Up @@ -46,9 +46,9 @@ describe.each([CASE_PASSING, CASE_FAILING])('runAsyncTest: %s', testCase => {
}));

testObject = new VestTest({
suiteId,
fieldName,
statement: STATEMENT,
suiteId,
testFn: testCase === CASE_PASSING ? Promise.resolve() : Promise.reject(),
});
setPending(suiteId, testObject);
Expand Down Expand Up @@ -162,9 +162,9 @@ describe.each([CASE_PASSING, CASE_FAILING])('runAsyncTest: %s', testCase => {
setPending(
suiteId,
new VestTest({
suiteId,
fieldName: 'pending_field',
statement: STATEMENT,
suiteId,
testFn: jest.fn(),
})
);
Expand Down
9 changes: 4 additions & 5 deletions packages/vest/src/index.js
Expand Up @@ -12,16 +12,15 @@ import singleton from './lib/singleton';

export default singleton.register(
{
any,
Enforce: enforce.Enforce,
VERSION,
enforce,

any,
create: createSuite,
test,
validate,
enforce,
reset,
runWithContext,
test,
validate,
...hooks,
},
state.register
Expand Down
4 changes: 2 additions & 2 deletions packages/vest/src/lib/singleton/index.js
Expand Up @@ -49,8 +49,8 @@ const set = (key, value) => (go[SYMBOL_VEST][key] = value);
const useContext = () => use().ctx;

export default {
use,
register,
set,
use,
useContext,
register,
};
8 changes: 4 additions & 4 deletions packages/vest/testUtils/isDeepCopy/index.js
@@ -1,7 +1,7 @@
const isDeepCopy = (source, clone) => {
const queue = [[source, clone]];

while (queue.length) {
outer: while (queue.length) {
const [source, clone] = queue.shift();

if (!source || typeof source !== 'object') {
Expand All @@ -21,7 +21,7 @@ const isDeepCopy = (source, clone) => {
Object.keys(source).forEach(key => queue.push([source[key], clone[key]]));
}

continue;
continue outer;
}
};

Expand All @@ -33,8 +33,8 @@ export const SAMPLE_DEEP_OBJECT = [
first: 'Velasquez',
last: 'Lara',
},
tags: ['Lorem', 'ullamco', 'minim', 'ut', 'ad'],
range: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
tags: ['Lorem', 'ullamco', 'minim', 'ut', 'ad'],
},
{
_id: '5eb4784e64618155ef167791',
Expand All @@ -43,7 +43,6 @@ export const SAMPLE_DEEP_OBJECT = [
first: 'Mcconnell',
last: 'Dennis',
},
tags: ['nulla', 'ex', 'et', 'sint', 'aliqua'],
range: [
{
a: 1,
Expand All @@ -55,6 +54,7 @@ export const SAMPLE_DEEP_OBJECT = [
],
},
],
tags: ['nulla', 'ex', 'et', 'sint', 'aliqua'],
},
];

Expand Down

0 comments on commit ce5edda

Please sign in to comment.