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 fea031a commit 33759d9
Show file tree
Hide file tree
Showing 41 changed files with 808 additions and 833 deletions.
177 changes: 1 addition & 176 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,176 +1 @@
env:
node: true
es6: true
extends: 'eslint:recommended'
globals:
api: false
application: false
connection: false
impress: false
rules:
indent:
- error
- 2
- SwitchCase: 1
VariableDeclarator:
var: 2
let: 2
const: 1
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: 5
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'
18 changes: 8 additions & 10 deletions lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ const splitAt = (
return [part1, part2];
};

const shuffle = (
// Shuffle an array
arr // array
// Returns: array
) => (
// Shuffle an array
// arr - array
// Returns: array
const shuffle = arr => (
arr.sort(() => Math.random() - 0.5)
);

Expand Down Expand Up @@ -59,11 +58,10 @@ const sequence = (
return res;
};

const last = (
// Get last element of array
arr // array
// Returns: element
) => (
// Get last element of array
// arr - array
// Returns: element
const last = arr => (
arr[arr.length - 1]
);

Expand Down
36 changes: 19 additions & 17 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,50 +41,50 @@ const passwordTests = {
MIN_LENGTH: {
test: (password, options) => password.length >= options.minLength,
hint: options => ({ name: 'MIN_LENGTH', minLength: options.minLength }),
options: { minLength: 10 }
options: { minLength: 10 },
},
MAX_LENGTH: {
test: (password, options) => password.length <= options.maxLength,
hint: options => ({ name: 'MAX_LENGTH', maxLength: options.maxLength }),
options: { maxLength: 128 }
options: { maxLength: 128 },
},
MIN_PASSPHRASE_LENGTH: {
test: (password, options) => password.length >= options.minLength,
hint: options => ({
name: 'MIN_PASSPHRASE_LENGTH',
minLength: options.minLength
minLength: options.minLength,
}),
options: { minLength: 20 }
options: { minLength: 20 },
},
MAX_REPEATED_CHARS: {
test: (password, options) => {
const regexp = new RegExp(`(.)\\1{${options.number},}`);
return !regexp.test(password);
},
hint: options => ({ name: 'MAX_REPEATED_CHARS', number: options.number }),
options: { number: 2 }
options: { number: 2 },
},
MIN_LOWERCASE_CHARS: {
test: (password, option) => (
stringIncludesChars(password, unicodeCategories.Ll, option.number)
),
hint: options => ({ name: 'MIN_LOWERCASE_CHARS', number: options.number }),
options: { number: 1 }
options: { number: 1 },
},
MIN_UPPERCASE_CHARS: {
test: (password, options) => (
stringIncludesChars(password, unicodeCategories.Lu, options.number)
),
hint: options => ({ name: 'MIN_UPPERCASE_CHARS', number: options.number }),
options: { number: 1 }
options: { number: 1 },
},
MIN_NUMBERS: {
test: (password, options) => {
const NUMBERS_RANGE = [[49, 57]];
return stringIncludesChars(password, NUMBERS_RANGE, options.number);
},
hint: options => ({ name: 'MIN_NUMBERS', number: options.number }),
options: { number: 1 }
options: { number: 1 },
},
MIN_SPECIAL_CHARS: {
test: (password, options) => {
Expand All @@ -93,20 +93,20 @@ const passwordTests = {
return stringIncludesChars(password, SPECIAL_CHARS_RANGE, options.number);
},
hint: options => ({ name: 'MIN_SPECIAL_CHARS', number: options.number }),
options: { number: 1 }
}
options: { number: 1 },
},
};

const loginTests = {
MIN_LENGTH: {
test: (login, options) => login.length >= options.minLength,
hint: options => ({ name: 'MIN_LENGTH', minLength: options.minLength }),
options: { minLength: 6 }
options: { minLength: 6 },
},
MAX_LENGTH: {
test: (login, options) => login.length <= options.maxLength,
hint: options => ({ name: 'MAX_LENGTH', maxLength: options.maxLength }),
options: { maxLength: 50 }
options: { maxLength: 50 },
},
IS_EMAIL: {
test: login => {
Expand All @@ -123,9 +123,11 @@ const loginTests = {
localPart.length <= MAX_LOCAL_PART_LENGTH &&
EMAIL_REGEXP.test(login);
}

return false;
},
hint: () => ({ name: 'IS_EMAIL' }),
}
},
};

const loginPasswordTests = {
Expand All @@ -136,7 +138,7 @@ const loginPasswordTests = {
PASSWORD_INCLUDES_LOGIN: {
test: (login, password) => !password.includes(login),
hint: () => ({ name: 'PASSWORD_INCLUDES_LOGIN' }),
}
},
};

class AuthenticationStrength {
Expand Down Expand Up @@ -220,7 +222,7 @@ const checkPassword = (
'MIN_NUMBERS',
'MIN_SPECIAL_CHARS',
'MIN_UPPERCASE_CHARS',
'MIN_LOWERCASE_CHARS'
'MIN_LOWERCASE_CHARS',
];
}
return makeTest(passwordTests, required, optional, password);
Expand All @@ -237,7 +239,7 @@ const checkLoginPassword = (
if (!required) {
required = [
'PASSWORD_INCLUDES_LOGIN',
'LOGIN_INCLUDES_PASSWORD'
'LOGIN_INCLUDES_PASSWORD',
];
}
return makeTest(loginPasswordTests, required, optional, login, password);
Expand All @@ -246,5 +248,5 @@ const checkLoginPassword = (
module.exports = {
checkLogin,
checkPassword,
checkLoginPassword
checkLoginPassword,
};
Loading

0 comments on commit 33759d9

Please sign in to comment.