Skip to content

Commit

Permalink
feature(putout) add eslint_only
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Oct 21, 2020
1 parent 8baba72 commit 62eeea1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
12 changes: 12 additions & 0 deletions packages/putout/.eslintrc.js
Expand Up @@ -15,6 +15,7 @@ module.exports = {
plugins: [
'node',
'putout',
'markdown',
],
overrides: [{
files: ['bin/**/*.js'],
Expand All @@ -27,6 +28,17 @@ module.exports = {
rules: {
'node/no-unpublished-require': 'off',
},
}, {
files: ['*.md'],
rules: {
'node/no-extraneous-require': 'off',
'putout/putout': ['error', {
rules: {
'remove-unused-expressions': 'off',
'strict-mode': 'off',
},
}],
},
}],
};

3 changes: 2 additions & 1 deletion packages/putout/.madrun.js
Expand Up @@ -20,9 +20,10 @@ module.exports = {
'.madrun.js',
'.eslintrc.js',
'test',
'*.md',
].join(' ');

return `bin/putout.js ${names}`;
return `ESLINT_ONLY=md bin/putout.js ${names}`;
},
'fix:lint': () => run('lint', '--fix'),
'fix:lint:fresh': () => run('fix:lint', '--fresh'),
Expand Down
10 changes: 5 additions & 5 deletions packages/putout/README.md
Expand Up @@ -217,16 +217,16 @@ const m = t + '!';
console.log(t);
`;

const result = putout(source, {
putout(source, {
plugins: [
'remove-unused-variables',
]
],
});
// returns
`
const t = 'hello';
console.log(t);
`
const t = 'hello',
console.log(t),
`;
```

## License
Expand Down
9 changes: 7 additions & 2 deletions packages/putout/lib/cli/index.js
Expand Up @@ -14,7 +14,12 @@ const {
STAGE,
} = require('./exit-codes');

const {PUTOUT_FILES = ''} = process.env;
const {env} = process;
const {
ESLINT_ONLY = '',
PUTOUT_FILES = '',
} = env;

const envNames = !PUTOUT_FILES ? [] : PUTOUT_FILES.split(',');

const {isArray} = Array;
Expand Down Expand Up @@ -170,14 +175,14 @@ module.exports = async ({argv, halt, log, write, logError}) => {
enable,
enableAll,
},

exit,
log,
logError,
write,
transform,
noConfig: !args.config,
plugins: args.plugins,
eslintOnly: ESLINT_ONLY,
};

const rawPlaces = [];
Expand Down
24 changes: 15 additions & 9 deletions packages/putout/lib/cli/process-file.js
Expand Up @@ -54,7 +54,7 @@ function getOptions({noConfig, plugins, name, transform, rulesdir}) {
};
}

module.exports = ({write, fix, debug, transform, fileCache, fixCount, rulesdir, format, isFlow, isJSX, ruler, logError, raw, exit, noConfig, plugins = []}) => async (name, index, {length}) => {
module.exports = ({write, fix, debug, transform, fileCache, fixCount, rulesdir, format, isFlow, isJSX, ruler, logError, raw, exit, noConfig, plugins = [], eslintOnly}) => async (name, index, {length}) => {
const resolvedName = resolve(name)
.replace(/^\./, cwd);

Expand Down Expand Up @@ -105,14 +105,20 @@ module.exports = ({write, fix, debug, transform, fileCache, fixCount, rulesdir,
return places;
}

const [e, result] = tryCatch(putout, source, {
fix,
fixCount,
isTS,
isFlow,
isJSX,
...options,
});
let e;
let result = {
places: [],
};

if (!RegExp(eslintOnly).test(resolvedName))
[e, result] = tryCatch(putout, source, {
fix,
fixCount,
isTS,
isFlow,
isJSX,
...options,
});

if (e) {
raw && logError(e);
Expand Down

0 comments on commit 62eeea1

Please sign in to comment.