diff --git a/src/config/__tests__/lintstagedrc.js b/src/config/__tests__/lintstagedrc.js deleted file mode 100644 index ce0f853..0000000 --- a/src/config/__tests__/lintstagedrc.js +++ /dev/null @@ -1,42 +0,0 @@ -/* eslint-disable no-use-before-define */ -import * as utilsMock from '../../utils'; - -jest.mock('../../utils', () => ({ - ...require.requireActual('../../utils'), - isOptedOut: jest.fn((key, t) => t), -})); - -afterEach(() => { - jest.resetModules(); -}); - -test('includes format and git add when not opted out', () => { - utilsMock.isOptedOut.mockImplementation((key, t, f) => f); - const config = require('../lintstagedrc'); - const jsLinter = getJsLinter(config.linters); - expect(hasFormat(jsLinter)).toBe(true); - expect(hasGitAdd(jsLinter)).toBe(true); -}); - -test('does not include format and git add when opted out', () => { - utilsMock.isOptedOut.mockImplementation((key, t) => t); - const config = require('../lintstagedrc'); - const jsLinter = getJsLinter(config.linters); - expect(hasFormat(jsLinter)).toBe(false); - expect(hasGitAdd(jsLinter)).toBe(false); -}); - -function hasFormat(linter) { - return linter.some(l => l.includes('format')); -} - -function hasGitAdd(linter) { - return linter.includes('git add'); -} - -function getJsLinter(linters) { - const key = Object.keys(linters).find( - k => k.includes('**') && k.includes('js'), - ); - return linters[key]; -} diff --git a/src/config/lintstagedrc.js b/src/config/lintstagedrc.js index 845e252..21080a5 100644 --- a/src/config/lintstagedrc.js +++ b/src/config/lintstagedrc.js @@ -1,4 +1,4 @@ -const { resolveFransScripts, resolveBin, isOptedOut } = require('../utils'); +const { resolveFransScripts, resolveBin } = require('../utils'); const fransScripts = resolveFransScripts(); const doctoc = resolveBin('doctoc'); @@ -12,10 +12,10 @@ module.exports = { 'git add README.md', ], '**/*.+(js|jsx|json|less|scss|sass|css|ts|md)': [ - isOptedOut('autoformat', null, `${fransScripts} format`), + `${fransScripts} format`, `${fransScripts} test --passWithNoTests --findRelatedTests`, `${fransScripts} lint`, - isOptedOut('autoformat', null, 'git add'), + 'git add', ].filter(Boolean), }, }; diff --git a/src/scripts/precommit.js b/src/scripts/precommit.js index eddebe0..51a2316 100644 --- a/src/scripts/precommit.js +++ b/src/scripts/precommit.js @@ -1,7 +1,6 @@ const path = require('path'); const spawn = require('cross-spawn'); const { - isOptedIn, resolveBin, hasFile, hasPkgProp, @@ -27,7 +26,7 @@ const lintStagedResult = spawn.sync(resolveBin('lint-staged'), [...config], { stdio: 'inherit', }); -if (lintStagedResult.status !== 0 || !isOptedIn('pre-commit')) { +if (lintStagedResult.status !== 0) { process.exit(lintStagedResult.status); } else { const validateResult = spawn.sync( diff --git a/src/utils.js b/src/utils.js index 1935d71..aa39246 100644 --- a/src/utils.js +++ b/src/utils.js @@ -125,24 +125,6 @@ function getConcurrentlyArgs(scripts, { killOthers = true } = {}) { ].filter(Boolean) } -function isOptedOut(key, t = true, f = false) { - if (!fs.existsSync(fromRoot('.opt-out'))) { - return f; - } - - const contents = fs.readFileSync(fromRoot('.opt-out'), 'utf-8'); - return contents.includes(key) ? t : f; -} - -function isOptedIn(key, t = true, f = false) { - if (!fs.existsSync(fromRoot('.opt-in'))) { - return f; - } - - const contents = fs.readFileSync(fromRoot('.opt-in'), 'utf-8'); - return contents.includes(key) ? t : f; -} - const getPackageManagerBin = () => { try { resolveBin('yarn'); @@ -168,8 +150,6 @@ module.exports = { ifFile, ifPeerDep, ifScript, - isOptedIn, - isOptedOut, parseEnv, pkg, resolveBin,