Created
March 29, 2017 06:39
-
-
Save yyscamper/00eee65d1a9aac67ff1640ddbc54672e to your computer and use it in GitHub Desktop.
Convert ESLint airbnb JavaScript config into single file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var _ = require('lodash'); | |
var airbnb = require('eslint-config-airbnb'); | |
var yaml = require('js-yaml'); | |
function load(filename) { | |
console.log('load file ' + filename); | |
return require(filename); | |
} | |
function parse(obj) { | |
if (obj.hasOwnProperty('extends')) { | |
var newObj = _.reduce(obj.extends, function(acc, file) { | |
if (_.endsWith(file, 'react.js') || _.endsWith(file, 'react-a11y.js')) { | |
return acc; | |
} | |
return _.defaultsDeep(parse(load(file)), acc); | |
}, obj); | |
delete newObj.extends; | |
obj = newObj; | |
} | |
return obj; | |
} | |
var result = parse(airbnb); | |
require('fs').writeFileSync('.eslintrc', JSON.stringify(result, null, ' ')); | |
require('fs').writeFileSync('.eslintrc.yml', yaml.safeDump(result, { indent: 2, sortKeys: true })); | |
console.log('DONE!'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The result is put into another gist: https://gist.github.com/yyscamper/3e1c7e7262231f53c66df8c389b23822