Skip to content

Commit

Permalink
chore: setup repository for TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
jdbruijn committed Sep 6, 2020
1 parent 7cdba63 commit 1f38e86
Show file tree
Hide file tree
Showing 5 changed files with 7,434 additions and 2,148 deletions.
69 changes: 56 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const defaultConfig = {
extends: [
'eslint:recommended',
'plugin:json/recommended',
'plugin:prettier/recommended',
],
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
plugins: [],
parserOptions: {
sourceType: 'module',
Expand All @@ -13,27 +9,74 @@ const defaultConfig = {
node: true,
},
rules: {
'no-restricted-globals': [
'error',
/**
* From Jest global environment.
* https://github.com/facebook/jest/blob/v26.4.2/packages/jest-globals/src/index.ts#L12-L27
*/
'jest',
'expect',
'it',
'test',
'fit',
'xit',
'xtest',
'describe',
'xdescribe',
'fdescribe',
'beforeAll',
'beforeEach',
'afterEach',
'afterAll',
],
'prettier/prettier': 'error',
'sort-imports': 'error',
},
};

/**
* Add to `extends` of `defaultConfig`.
*
* The Prettier recommended configuration must be the last extension. See
* https://github.com/prettier/eslint-plugin-prettier#recommended-configuration.
*
* @param {...configurations} configurations Configuration(s) to add.
* @return Superset of the `extends` with the given configuration(s) added.
*/
function addToDefaultExtends(...configurations) {
const prettierConfiguration = 'plugin:prettier/recommended';
const extendsSuperset = defaultConfig.extends
.concat(configurations)
.sort((a, b) => {
if (b === prettierConfiguration) {
return -1;
}
if (a === prettierConfiguration) {
return 1;
}
return 0;
});

return extendsSuperset;
}

const config = defaultConfig;
config.overrides = [
{
files: ['**/*.ts', '**/*.tsx'],
/**
* The Prettier recommended configuration must remain the configuration that
* is extended last. Therefore, this overrides `extends` completely.
*/
extends: [
'eslint:recommended',
extends: addToDefaultExtends(
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
'plugin:jest/style',
),
parser: '@typescript-eslint/parser',
plugins: defaultConfig.plugins.concat(['@typescript-eslint']),
rules: { ...defaultConfig.rules, 'jest/consistent-test-it': 'error' },
},
{
files: ['**/*.json'],
extends: addToDefaultExtends('plugin:json/recommended'),
},
];

Expand Down
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts'],
coverageDirectory: 'coverage',
coverageReporters: ['cobertura', 'lcov', 'text'],
preset: 'ts-jest',
roots: ['<rootDir>/src'],
};
Loading

0 comments on commit 1f38e86

Please sign in to comment.