Skip to content

Instantly share code, notes, and snippets.

@fand
Created October 1, 2015 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fand/0a9ffc5f82adf1908569 to your computer and use it in GitHub Desktop.
Save fand/0a9ffc5f82adf1908569 to your computer and use it in GitHub Desktop.
勤怠と同時にESLint設定かえるくん
'use strict';
var fs = require('fs-promise');
var SECRET = require('../SECRET');
module.exports = function (mode) {
// ESLint設定を変更する
var indentValue;
if (mode === 'IN') {
indentValue = '[2, 4, {"SwitchCase": 0}],';
}
if (mode === 'OUT') {
indentValue = '[2, 2, {"SwitchCase": 0}],';
}
var errors = [];
return fs.readFile(SECRET.ESLINT_PATH, 'utf8')
.then(function (eslint) {
var lines = eslint.split('\n');
// indent設定を置換
var newLines = lines.map(function (line) {
var m = line.match(/^(\s*\"indent\"\s*\:\s*).*$/);
if (m) {
return m[1] + indentValue;
}
else {
return line;
}
});
return newLines.join('\n');
})
.catch(function (error) {
console.error('.eslintrcの読み込みに失敗しました(◞‸◟)');
errors.push(error);
})
.then(function (newEslint) {
if (newEslint) {
return fs.writeFile(SECRET.ESLINT_PATH, newEslint, 'utf8');
}
})
.catch(function () {
console.error('.eslintrcの書き込みに失敗しました(◞‸◟)');
errors.push(error);
})
.then(function () {
if (errors.length > 0) {
return Promise.reject(errors);
}
return Promise.resolve();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment