Skip to content

Commit

Permalink
build(lint): apply enforced ESLint to project
Browse files Browse the repository at this point in the history
+ Install ESLint
+ Fix errors from ESLint
+ Add hook to run lint before commiting

BREAKING CHANGE: Enforce linting in the deploy process
  • Loading branch information
samir-araujo committed Apr 10, 2020
1 parent e7f11d0 commit f75b26c
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 32 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
indent: ['error', 4],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
camelcase: 'off',
'@typescript-eslint/camelcase': 'off',
},
};
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
"@types/jest": "^25.1.4",
"@types/lodash": "^4.14.149",
"@types/node": "^13.9.5",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"agadoo": "^2.0.0",
"babel-jest": "^25.2.4",
"commitizen": "^4.0.3",
"coveralls": "^3.0.11",
"cross-env": "^7.0.2",
"cz-conventional-changelog": "3.1.0",
"eslint": "^6.8.0",
"husky": "^4.2.3",
"jest": "^25.2.4",
"lint-staged": ">=10",
"lodash": "^4.17.15",
"np": "^6.2.0",
"semantic-release": "^17.0.4",
Expand All @@ -38,6 +42,7 @@
"scripts": {
"commit": "git-cz",
"build": "tsc",
"lint": "eslint '**/*.ts' --fix --ignore-pattern node_modules/ --ignore-pattern lib/",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
Expand Down Expand Up @@ -70,7 +75,11 @@
"husky": {
"hooks": {
"prepare-commit-msg": "exec < /dev/tty && git cz --hook || true",
"pre-push": "yarn test"
"pre-push": "yarn test",
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": "eslint --cache --fix"
}
}
15 changes: 12 additions & 3 deletions src/helpers/__tests__/getLocale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@ import getLocale from '../getLocale';

describe('Helpers | getLocale', () => {
it('returns requested locale from given locale collection', () => {
const locales: LocaleObject<string[]> = { en: ['en'], pt_BR: ['pt_BR'] };
const locales: LocaleObject<string[]> = {
en: ['en'],
pt_BR: ['pt_BR'],
};

const locale = getLocale(locales, Locale.PT_BR);

expect(locale).toEqual(['pt_BR']);
});

it(`returns ${Locale.EN} locale by default`, () => {
const locales: LocaleObject<string[]> = { en: ['en'], pt_BR: ['pt_BR¿'] };
const locales: LocaleObject<string[]> = {
en: ['en'],
pt_BR: ['pt_BR¿'],
};

const locale = getLocale(locales);

expect(locale).toEqual(['en']);
});

it(`returns ${Locale.EN} if given locale is invalid`, () => {
const locales: LocaleObject<string[]> = { en: ['en'], pt_BR: ['pt_BR¿'] };
const locales: LocaleObject<string[]> = {
en: ['en'],
pt_BR: ['pt_BR¿'],
};

const locale = getLocale(locales, Locale.RU);

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/randomNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import random from 'lodash/random';
* @param {boolean} [isFloating=false]
* @returns {number}
*/
export default function randomNumber(min?: number, max?: number, isFloating: boolean = false): number {
export default function randomNumber(min?: number, max?: number, isFloating = false): number {
if (min === undefined) {
min = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/name/firstName/locales/en/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ const collection: string[] = [
'Dana',
'Dandre',
'Dane',
"D'angelo",
'D\'angelo',
'Dangelo',
'Danial',
'Daniela',
Expand Down
2 changes: 1 addition & 1 deletion src/name/lastName/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getLocale from '../../helpers/getLocale';
import locales from './locales';
import randomArrayElement from '../../helpers/randomArrayElement';

export default function lastName(selectedLocale?: Locale) {
export default function lastName(selectedLocale?: Locale): string {
const collection = getLocale(locales, selectedLocale);

return randomArrayElement(collection);
Expand Down
14 changes: 7 additions & 7 deletions src/name/lastName/locales/en/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ export default [
'Ziemann',
'Zieme',
'Zulauf',
"D'Amore",
"O'Connell",
"O'Conner",
"O'Hara",
"O'Keefe",
"O'Kon",
"O'Reilly",
'D\'Amore',
'O\'Connell',
'O\'Conner',
'O\'Hara',
'O\'Keefe',
'O\'Kon',
'O\'Reilly',
];
4 changes: 2 additions & 2 deletions src/types/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ export enum Locale {
ZH_SG = 'zh_SG',
ZH_TW = 'zh_TW',
ZU = 'zu',
ZU_ZA = 'zu_ZA'
ZU_ZA = 'zu_ZA',
}

export type LocaleObject<T = any> = {
export type LocaleObject<T = string> = {
[K in Locale]?: T;
};
Loading

0 comments on commit f75b26c

Please sign in to comment.