Skip to content

Instantly share code, notes, and snippets.

@ronapelbaum
Created June 13, 2017 11:41
Show Gist options
  • Save ronapelbaum/2855a4c6d1f6cd2bb23d69db7bdf583d to your computer and use it in GitHub Desktop.
Save ronapelbaum/2855a4c6d1f6cd2bb23d69db7bdf583d to your computer and use it in GitHub Desktop.
Remove the `/* eslint-disable */` comment at file header, for changed files on branch

When you try to add eslint to a large project, you better try this approach as in this script.

Now, you want to enforce your team members to actually remove the /* eslint-disable */ comment at file header, for all files that they've changed.

Here you go.

const proc = require('child_process');
const fs = require('fs');
const run = command => proc.execSync(command, {encoding: 'utf8'}).trim();
const getChangedFiles = () => run('git diff --name-only master').split('\n');
const removeFirstLine = data => data.split('\n').slice(1).join('\n');
function stripDisableString(file) {
const content = fs.readFileSync(file, 'utf8');
if (content.startsWith('/* eslint-disable */')) {
fs.writeFileSync(file, removeFirstLine(content), 'utf8');
}
}
getChangedFiles().forEach(stripDisableString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment