Skip to content

Commit

Permalink
Use eslint-config-skuba (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
72636c authored Jun 19, 2020
1 parent b480dac commit f2f3925
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 99 deletions.
14 changes: 14 additions & 0 deletions .changeset/five-glasses-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'skuba': minor
---

**eslint:** skuba is now usable as a shareable config

```javascript
// .eslintrc.js

module.exports = {
// This can be used in place of require.resolve('skuba/config/eslint')
extends: ['skuba'],
};
```
9 changes: 2 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
const config = require('./config/eslint');

module.exports = {
...config,

extends: ['skuba'],
rules: {
...config.rules,

// internal to skuba
// internal to skuba itself
'no-process-exit': 'off',
},
};
82 changes: 1 addition & 81 deletions config/eslint.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,3 @@
module.exports = {
extends: [
'seek',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
ignorePatterns: ['**/.eslintrc.js'],
overrides: [
{
files: ['**/jest.*config*.js'],
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'import/no-unresolved': 'off',
},
},
{
files: ['**/*.test.ts'],
rules: {
// Allow `any` in tests
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',

// Allow e.g. expect(logger.child).toBeCalledWith
'@typescript-eslint/unbound-method': 'off',
},
},
],
parserOptions: {
project: './tsconfig.json',
},
plugins: ['eslint-plugin-tsdoc'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-floating-promises': 'error',

'import/no-duplicates': 'error',
'import/order': [
'error',
{
alphabetize: {
order: 'asc',
},
'newlines-between': 'always',
pathGroups: [
{
group: 'external',
pattern: 'src',
position: 'after',
},
{
group: 'external',
pattern: 'src/**',
position: 'after',
},
],
pathGroupsExcludedImportTypes: ['builtin'],
},
],

'jest/expect-expect': 'off',
'jest/no-deprecated-functions': 'error',
'jest/prefer-spy-on': 'error',
'jest/prefer-strict-equal': 'off',
'jest/prefer-to-be-null': 'error',
'jest/prefer-to-be-undefined': 'error',
'jest/prefer-to-contain': 'error',
'jest/prefer-to-have-length': 'error',
'jest/prefer-todo': 'error',
'jest/valid-title': 'error',

'tsdoc/syntax': 'error',

'no-use-before-define': 'off',
'sort-imports': [
'error',
{
ignoreDeclarationSort: true,
},
],
},
extends: ['skuba'],
};
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
"ejs": "^3.1.3",
"enquirer": "^2.3.5",
"eslint": "^7.2.0",
"eslint-config-seek": "^7.0.1",
"eslint-plugin-jest": "^23.13.2",
"eslint-plugin-tsdoc": "^0.2.5",
"eslint-config-skuba": "1.0.0",
"execa": "^4.0.2",
"fs-extra": "^9.0.1",
"get-port": "^5.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ node_modules*/
},
".eslintrc.js": Object {
"data": "module.exports = {
extends: [require.resolve('skuba/config/eslint')],
extends: ['skuba'],
};
",
"operation": "A",
Expand Down
25 changes: 20 additions & 5 deletions src/cli/configure/modules/eslint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('eslintModule', () => {
defaultOpts,
);

expect(outputFiles['.eslintrc.js']).toContain('skuba/config/eslint');
expect(outputFiles['.eslintrc.js']).toContain('skuba');
});

it('deletes rogue configs', async () => {
Expand All @@ -35,7 +35,7 @@ describe('eslintModule', () => {
);

expect(outputFiles['.eslintrc']).toBeUndefined();
expect(outputFiles['.eslintrc.js']).toContain('skuba/config/eslint');
expect(outputFiles['.eslintrc.js']).toContain('skuba');
expect(outputFiles['.eslintrc.yml']).toBeUndefined();
expect(outputFiles['package.json']).toContain('secret-service');
expect(outputFiles['package.json']).not.toContain('eslintConfig');
Expand All @@ -52,14 +52,29 @@ describe('eslintModule', () => {
defaultOpts,
);

expect(outputFiles['.eslintrc.js']).toContain('skuba/config/eslint');
expect(outputFiles['.eslintrc.js']).toContain('skuba');
expect(outputFiles['.eslintrc.js']).not.toContain('skydive');
});

it('preserves extended config', async () => {
it('preserves config extending module import', async () => {
const inputFiles = {
'.eslintrc.js':
"module.exports = { extends: ['skuba/config/eslint'], rules: [] }",
"module.exports = { extends: [require.resolve('skuba/config/eslint')], rules: { 'no-process-exit': 'off' } }",
};

const outputFiles = await executeModule(
eslintModule,
inputFiles,
defaultOpts,
);

expect(outputFiles['.eslintrc.js']).toBe(inputFiles['.eslintrc.js']);
});

it('preserves config extending shareable config', async () => {
const inputFiles = {
'.eslintrc.js':
"module.exports = { extends: ['skuba'], rules: { 'no-process-exit': 'off' } }",
};

const outputFiles = await executeModule(
Expand Down
2 changes: 1 addition & 1 deletion src/cli/configure/modules/eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const eslintModule = async (): Promise<Module> => {

// allow customised ESLint configs that extend skuba
'.eslintrc.js': (inputFile) =>
inputFile?.includes('skuba/config/eslint') ? inputFile : configFile,
inputFile?.includes('skuba') ? inputFile : configFile,

'.eslintignore': mergeWithIgnoreFile(ignoreFile),

Expand Down
2 changes: 1 addition & 1 deletion template/base/_.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: [require.resolve('skuba/config/eslint')],
extends: ['skuba'],
};
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,15 @@ eslint-config-seek@^7.0.1:
eslint-plugin-react-hooks "^4.0.4"
find-root "^1.1.0"

[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-config-skuba/-/eslint-config-skuba-1.0.0.tgz#9bb9fb021c87dae20875bce0a0fa71afea41222a"
integrity sha512-kkzapb0xL9a7I+jY7+yLrQlEf8ichT1gq0P6Xo4UQp3NwaPQWnFOvGC0NAx19MdoG/ggUslXV/Ad8d0CehFtVQ==
dependencies:
eslint-config-seek "^7.0.1"
eslint-plugin-jest "^23.13.2"
eslint-plugin-tsdoc "^0.2.5"

eslint-import-resolver-node@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.3.tgz#dbaa52b6b2816b50bc6711af75422de808e98404"
Expand Down

0 comments on commit f2f3925

Please sign in to comment.