Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Commit

Permalink
Use extends in overrides
Browse files Browse the repository at this point in the history
Now eslint/eslint#8813 is fixed this leads to much less object merging
  • Loading branch information
Charlie Briggs committed Jul 9, 2019
1 parent 90ab405 commit e9d7561
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 53 deletions.
43 changes: 17 additions & 26 deletions rules/auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,25 @@ const getConfig = ({ prettier = true, esModules = false }) => {
config.settings = { react: { pragma: 'h' } };
}

const getJestConfig = () => {
// Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
const jestConfig = require('./jest');
return Object.assign({}, jestConfig, {
files: [
'**/__tests__/**/*.js',
'**/__mocks__/**/*.js',
'test/**/*.js',
'test/**/*.jsx',
],
});
};
const getJestConfig = () => ({
files: [
'**/__tests__/**/*.js',
'**/__mocks__/**/*.js',
'test/**/*.js',
'test/**/*.jsx',
],
extends: path.join(__dirname, './jest.js'),
});

const getMochaConfig = () => {
// Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
const mochaConfig = require('../mocha');
return Object.assign({}, mochaConfig, {
files: ['**/*.test.js', '**/*.spec.js'],
});
};
const getMochaConfig = () => ({
files: ['**/*.test.js', '**/*.spec.js'],
extends: path.join(__dirname, './mocha.js'),
});

const getCypressConfig = () => {
// Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
const cypressConfig = require('./cypress');
return Object.assign({}, cypressConfig, {
files: ['cypress/**/*.js'],
});
};
const getCypressConfig = () => ({
files: ['cypress/**/*.js'],
extends: path.join(__dirname, './cypress.js'),
});

config.extends = usingJsx
? [path.join(__dirname, './react.js')]
Expand Down
13 changes: 6 additions & 7 deletions rules/cypress.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

const cypressConfig = require('eslint-plugin-cypress').configs.recommended;
const mochaConfig = require('./mocha');
const path = require('path');

const mergedConfig = Object.assign({}, mochaConfig, {
const mergedConfig = {
extends: ['plugin:cypress/recommended', path.join(__dirname, './mocha.js')],
// Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
rules: Object.assign({}, mochaConfig.rules, cypressConfig.rules, {
rules: {
// allow top-level hooks in cypress setup files
'mocha/no-top-level-hooks': 'off',
// allow dev-deps in cypress test directories
Expand All @@ -16,8 +16,7 @@ const mergedConfig = Object.assign({}, mochaConfig, {
optionalDependencies: false,
},
],
}),
plugins: [...(mochaConfig.plugins || []), ...(cypressConfig.plugins || [])],
});
},
};

module.exports = mergedConfig;
35 changes: 15 additions & 20 deletions rules/jest.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
'use strict';

const jestConfig = require('eslint-plugin-jest').configs.recommended;
const { usingJsx } = require('../lib/feature-detect');

// Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
// the default jest/globals with jest/recommended doesn't work with eslint@5.x.x
// https://github.com/jest-community/eslint-plugin-jest/issues/128
jestConfig.env = {
jest: true,
const config = {
extends: ['plugin:jest/recommended'],
rules: {
// This disallows .skip, which is auseful tool for writing skelton tests
// prior to full implementation. no-focused-tests is still enabled, which
// catches .only - that's the killer
'jest/no-disabled-tests': [0, { extensions: ['.js', '.jsx'] }],

// Disable as it's frequently necessary to do inline requires
// when working with jest mocks
'global-require': 'off',
},
};

if (usingJsx) {
// allow test files to contain jsx but still keep the .js extension
jestConfig.rules['react/jsx-filename-extension'] = [
config.rules['react/jsx-filename-extension'] = [
'error',
{ extensions: ['.js', '.jsx'] },
];
}

// This disallows .skip, which is auseful tool for writing skelton tests
// prior to full implementation. no-focused-tests is still enabled, which
// catches .only - that's the killer
jestConfig.rules['jest/no-disabled-tests'] = [
0,
{ extensions: ['.js', '.jsx'] },
];

// Disable as it's frequently necessary to do inline requires
// when working with jest mocks
jestConfig.rules['global-require'] = 'off';

module.exports = jestConfig;
module.exports = config;

0 comments on commit e9d7561

Please sign in to comment.