Socket
Socket
Sign inDemoInstall

editorconfig

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

editorconfig - npm Package Compare versions

Comparing version 0.11.4 to 0.12.0

142

editorconfig.js

@@ -1,3 +0,4 @@

var fs = require('fs');
var path = require('path');
var Promise = require('bluebird');
var whenReadFile = Promise.promisify(require('fs').readFile);

@@ -9,7 +10,14 @@ var minimatch = require('./lib/fnmatch');

var knownProps = [
'end_of_line',
'indent_style',
'indent_size',
'insert_final_newline',
'trim_trailing_whitespace',
'charset'
].reduce(function (set, prop) {
set[prop] = true;
return set;
}, {});
var knownProps = ['end_of_line', 'indent_style', 'indent_size',
'insert_final_newline', 'trim_trailing_whitespace', 'charset'];
function fnmatch(filepath, glob) {

@@ -21,12 +29,8 @@ var matchOptions = {matchBase: true, dot: true, noext: true};

function getConfigFileNames(filepath, configname) {
var old_dirname = filepath;
var dirname = old_dirname;
function getConfigFileNames(filepath, options) {
var paths = [];
do {
paths.push(path.join(dirname, configname || ".editorconfig"));
old_dirname = dirname;
dirname = path.dirname(old_dirname);
} while(dirname != old_dirname);
filepath = path.dirname(filepath);
paths.push(path.join(filepath, options.config));
} while (filepath !== options.root);
return paths;

@@ -36,3 +40,2 @@ }

function processMatches(matches, version) {
// Set indent_size to "tab" if indent_size is unspecified and

@@ -59,86 +62,87 @@ // indent_style is set to "tab".

function processOptions(options) {
options = options || {};
options.version = new Version(options.version || pkg.version);
return options;
return {
config: options.config || '.editorconfig',
version: new Version(options.version || pkg.version),
root: path.resolve(options.root || '/')
};
}
function parseFromFiles(filepath, configs, options) {
var matches = {};
configs.reverse().forEach(function (file) {
function parseFromFiles(filepath, files, options) {
return getConfigsForFiles(files).then(function (configs) {
return configs.reverse();
}).reduce(function (matches, file) {
var pathPrefix = path.dirname(file.name);
var config = file.contents;
config.forEach(function (section) {
var fullGlob;
var glob = section[0];
var options = section[1];
file.contents.forEach(function (section) {
var glob = section[0], options = section[1];
if (!glob) return;
if (glob.indexOf('/') === -1) {
fullGlob = path.join(pathPrefix, "**/" + glob);
} else if (glob.indexOf('/') === 0) {
fullGlob = path.join(pathPrefix, glob.substring(1));
} else {
fullGlob = path.join(pathPrefix, glob);
switch (glob.indexOf('/')) {
case -1: glob = "**/" + glob; break;
case 0: glob = glob.substring(1); break;
}
if (fnmatch(filepath, fullGlob)) {
for (var key in options) {
var value = options[key];
if (knownProps.indexOf(key) !== -1) {
value = value.toLowerCase();
}
try {
value = JSON.parse(value);
} catch(e){}
matches[key.toLowerCase()] = value;
var fullGlob = path.join(pathPrefix, glob);
if (!fnmatch(filepath, fullGlob)) return;
for (var key in options) {
var value = options[key];
key = key.toLowerCase();
if (knownProps[key]) {
value = value.toLowerCase();
}
try {
value = JSON.parse(value);
} catch(e) {}
matches[key] = value;
}
});
return matches;
}, {}).then(function (matches) {
return processMatches(matches, options.version);
});
}
return processMatches(matches, options.version);
function StopReduce(array) {
this.array = array;
}
StopReduce.prototype = Object.create(Error.prototype);
function getConfigsForFiles(files) {
var configs = [];
for (var i = 0; i < files.length; i++) {
files[i].contents = iniparser.parseString(files[i].contents);
configs.push(files[i]);
if (/^true$/i.test(files[i].contents[0][1].root)) break;
}
return configs;
return Promise.reduce(files, function (configs, file) {
var contents = iniparser.parseString(file.contents);
configs.push({
name: file.name,
contents: contents
});
if ((contents[0][1].root || '').toLowerCase() === 'true') {
return Promise.reject(new StopReduce(configs));
}
return configs;
}, []).catch(StopReduce, function (stop) {
return stop.array;
});
}
function readConfigFiles(filepaths) {
var files = [];
filepaths.forEach(function (configFilePath) {
if (fs.existsSync(configFilePath)) {
files.push({
name: configFilePath,
contents: fs.readFileSync(configFilePath, 'utf-8')
});
}
return Promise.map(filepaths, function (path) {
return whenReadFile(path, 'utf-8').catch(function () {
return '';
}).then(function (contents) {
return {name: path, contents: contents};
});
});
return files;
}
module.exports.parseFromFiles = function(filepath, files, options) {
module.exports.parseFromFiles = function (filepath, files, options) {
filepath = path.resolve(filepath);
options = processOptions(options);
return parseFromFiles(filepath, getConfigsForFiles(files), options);
return parseFromFiles(filepath, files, options);
};
module.exports.parse = function(filepath, options) {
module.exports.parse = function (filepath, options) {
filepath = path.resolve(filepath);
options = processOptions(options);
var filepaths = getConfigFileNames(path.dirname(filepath), options.config);
var filepaths = getConfigFileNames(filepath, options);
var files = readConfigFiles(filepaths);
return parseFromFiles(filepath, getConfigsForFiles(files), options);
return parseFromFiles(filepath, files, options);
};

@@ -0,0 +0,0 @@ // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>

@@ -0,0 +0,0 @@ // Based on iniparser by shockie <https://npmjs.org/package/iniparser>

@@ -0,0 +0,0 @@ function Version(version) {

{
"name": "editorconfig",
"version": "0.11.4",
"version": "0.12.0",
"description": "EditorConfig File Locator and Interpreter for Node.js",

@@ -23,3 +23,3 @@ "keywords": [

"test-verbose": "ctest -VV --output-on-failure .",
"codepaint": "codepaint xform -e **/**.js"
"codepaint": "codepainter xform -e **/**.js"
},

@@ -37,6 +37,10 @@ "repository": {

"dependencies": {
"bluebird": "^2.3.6",
"commander": "~1.1.1",
"lru-cache": "~2.0.0",
"sigmund": "~1.0.0"
},
"devDependencies": {
"codepainter": "^0.4.4"
}
}

@@ -0,0 +0,0 @@ # EditorConfig JavaScript Core

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc