Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
feat(precommit): Skip .opt-in and .opt-out
Browse files Browse the repository at this point in the history
Earlier the user had to opt-in to certain precommit hooks, mainly autoformat. Now it's not possible
to skip it.
  • Loading branch information
adambrgmn committed Dec 20, 2017
1 parent ecc4b25 commit 7dd8f35
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 67 deletions.
42 changes: 0 additions & 42 deletions src/config/__tests__/lintstagedrc.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/config/lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { resolveFransScripts, resolveBin, isOptedOut } = require('../utils');
const { resolveFransScripts, resolveBin } = require('../utils');

const fransScripts = resolveFransScripts();
const doctoc = resolveBin('doctoc');
Expand All @@ -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),
},
};
3 changes: 1 addition & 2 deletions src/scripts/precommit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const path = require('path');
const spawn = require('cross-spawn');
const {
isOptedIn,
resolveBin,
hasFile,
hasPkgProp,
Expand All @@ -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(
Expand Down
20 changes: 0 additions & 20 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -168,8 +150,6 @@ module.exports = {
ifFile,
ifPeerDep,
ifScript,
isOptedIn,
isOptedOut,
parseEnv,
pkg,
resolveBin,
Expand Down

0 comments on commit 7dd8f35

Please sign in to comment.