Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.1 to 0.11.2

116

editorconfig.js

@@ -7,5 +7,9 @@ var fs = require('fs');

var Version = require('./lib/version');
var package = require('./package.json');
var pkg = require('./package.json');
var knownProps = ['end_of_line', 'indent_style', 'indent_size',
'insert_final_newline', 'trim_trailing_whitespace', 'charset'];
function fnmatch(filepath, glob) {

@@ -36,3 +40,3 @@ var matchOptions = {matchBase: true, dot: true, noext: true};

!("indent_size" in matches) && version.gte(new Version(0, 10))) {
matches["indent_size"] = "tab";
matches.indent_size = "tab";
}

@@ -43,9 +47,9 @@

if ("indent_size" in matches && !("tab_width" in matches) &&
matches["indent_size"] !== "tab")
matches["tab_width"] = matches["indent_size"];
matches.indent_size !== "tab")
matches.tab_width = matches.indent_size;
// Set indent_size to tab_width if indent_size is "tab"
if("indent_size" in matches && "tab_width" in matches &&
matches["indent_size"] === "tab")
matches["indent_size"] = matches["tab_width"];
matches.indent_size === "tab")
matches.indent_size = matches.tab_width;

@@ -55,44 +59,21 @@ return matches;

function getOptions(options) {
if (typeof options === "undefined") {
options = {};
}
switch (typeof options.version) {
case "undefined":
options.version = new Version(package.version);
break;
case "string":
options.version = new Version(options.version);
break;
}
function processOptions(options) {
options = options || {};
options.version = new Version(options.version || pkg.version);
return options;
}
module.exports.parse = function(filepath, options) {
var filepaths;
var configurations = [];
var knownOptions = ['end_of_line', 'indent_style', 'indent_size',
'insert_final_newline', 'trim_trailing_whitespace', 'charset'];
function parseFromFiles(filepath, configs, options) {
var matches = {};
var parsedOutput;
options = getOptions(options);
filepaths = getConfigFileNames(path.dirname(filepath), options.config);
for (var i in filepaths) {
var configFilePath = filepaths[i];
if (fs.existsSync(configFilePath)) {
parsedOutput = iniparser.parseSync(configFilePath);
configurations.push([path.dirname(configFilePath), parsedOutput]);
if ((parsedOutput[0][1].root || "").toLowerCase() == "true") break;
}
}
for (var j in configurations.reverse()) {
var pathPrefix = configurations[j][0];
var config = configurations[j][1];
for (var k in config) {
var glob = config[k][0];
configs.reverse().forEach(function (file) {
var pathPrefix = path.dirname(file.name);
var config = file.contents;
config.forEach(function (section) {
var fullGlob;
if (!glob) continue;
var glob = section[0];
var options = section[1];
if (!glob) return;
if (glob.indexOf('/') === -1) {

@@ -106,5 +87,5 @@ fullGlob = path.join(pathPrefix, "**/" + glob);

if (fnmatch(filepath, fullGlob)) {
for (var m in config[k][1]) {
var value = config[k][1][m];
if (knownOptions.indexOf(m) !== -1) {
for (var key in options) {
var value = options[key];
if (knownProps.indexOf(key) !== -1) {
value = value.toLowerCase();

@@ -115,10 +96,51 @@ }

} catch(e){}
matches[m.toLowerCase()] = value;
matches[key.toLowerCase()] = value;
}
}
}
}
});
});
return processMatches(matches, options.version);
}
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;
}
function readConfigFiles(filepaths) {
var files = [];
filepaths.forEach(function (configFilePath) {
if (fs.existsSync(configFilePath)) {
files.push({
name: configFilePath,
contents: fs.readFileSync(configFilePath, 'utf-8')
});
}
});
return files;
}
module.exports.parseFromFiles = function(filepath, files, options) {
filepath = path.resolve(filepath);
options = processOptions(options);
return parseFromFiles(filepath, getConfigsForFiles(files), options);
};
module.exports.parse = function(filepath, options) {
filepath = path.resolve(filepath);
options = processOptions(options);
var filepaths = getConfigFileNames(path.dirname(filepath), options.config);
var files = readConfigFiles(filepaths);
return parseFromFiles(filepath, getConfigsForFiles(files), options);
};
{
"name": "editorconfig",
"version": "0.11.1",
"version": "0.11.2",
"description": "EditorConfig File Locator and Interpreter for Node.js",
"keywords": ["editorconfig", "core"],
"keywords": [
"editorconfig",
"core"
],
"main": "editorconfig.js",

@@ -12,3 +15,3 @@ "contributors": [

],
"directories" : {
"directories": {
"bin": "./bin",

@@ -22,4 +25,4 @@ "lib": "./lib"

"repository": {
"type": "git",
"url": "git://github.com/editorconfig/editorconfig-core-js.git"
"type": "git",
"url": "git://github.com/editorconfig/editorconfig-core-js.git"
},

@@ -26,0 +29,0 @@ "bugs": "https://github.com/editorconfig/editorconfig-core-js/issues",

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