Skip to content

Instantly share code, notes, and snippets.

@fand fand/eslint.js
Created Oct 1, 2015

Embed
What would you like to do?
勤怠と同時に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
You can’t perform that action at this time.