editorconfig
Advanced tools
Comparing version 0.12.2 to 0.13.0
var os = require('os'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var util = require('util'); | ||
var Promise = require('bluebird'); | ||
var whenReadFile = Promise.promisify(require('fs').readFile); | ||
var whenReadFile = Promise.promisify(fs.readFile); | ||
@@ -80,2 +82,30 @@ var minimatch = require('./lib/fnmatch'); | ||
function buildFullGlob(pathPrefix, glob) { | ||
switch (glob.indexOf('/')) { | ||
case -1: glob = "**/" + glob; break; | ||
case 0: glob = glob.substring(1); break; | ||
} | ||
return path.join(pathPrefix, glob); | ||
} | ||
function extendProps(props, options) { | ||
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) {} | ||
if (typeof value === 'undefined' || value === null) { | ||
// null and undefined are values specific to JSON (no special meaning | ||
// in editorconfig) & should just be returned as regular strings. | ||
value = String(value); | ||
} | ||
props[key] = value; | ||
} | ||
return props; | ||
} | ||
function parseFromFiles(filepath, files, options) { | ||
@@ -89,24 +119,5 @@ return getConfigsForFiles(files).then(function (configs) { | ||
if (!glob) return; | ||
switch (glob.indexOf('/')) { | ||
case -1: glob = "**/" + glob; break; | ||
case 0: glob = glob.substring(1); break; | ||
} | ||
var fullGlob = path.join(pathPrefix, glob); | ||
var fullGlob = buildFullGlob(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) {} | ||
if (typeof value === 'undefined' || value === null) { | ||
// null and undefined are values specific to JSON (no special meaning | ||
// in editorconfig) & should just be returned as regular strings. | ||
value = String(value); | ||
} | ||
matches[key] = value; | ||
} | ||
matches = extendProps(matches, options); | ||
}); | ||
@@ -119,2 +130,19 @@ return matches; | ||
function parseFromFilesSync(filepath, files, options) { | ||
var configs = getConfigsForFilesSync(files); | ||
configs.reverse(); | ||
var matches = {}; | ||
configs.forEach(function(config) { | ||
var pathPrefix = path.dirname(config.name); | ||
config.contents.forEach(function(section) { | ||
var glob = section[0], options = section[1]; | ||
if (!glob) return; | ||
var fullGlob = buildFullGlob(pathPrefix, glob); | ||
if (!fnmatch(filepath, fullGlob)) return; | ||
matches = extendProps(matches, options); | ||
}); | ||
}); | ||
return processMatches(matches, options.version); | ||
} | ||
function StopReduce(array) { | ||
@@ -142,2 +170,18 @@ this.array = array; | ||
function getConfigsForFilesSync(files) { | ||
var configs = []; | ||
for (var i in files) { | ||
var file = files[i]; | ||
var contents = iniparser.parseString(file.contents); | ||
configs.push({ | ||
name: file.name, | ||
contents: contents | ||
}); | ||
if ((contents[0][1].root || '').toLowerCase() === 'true') { | ||
break; | ||
} | ||
}; | ||
return configs; | ||
} | ||
function readConfigFiles(filepaths) { | ||
@@ -153,2 +197,16 @@ return Promise.map(filepaths, function (path) { | ||
function readConfigFilesSync(filepaths) { | ||
var files = []; | ||
var file; | ||
filepaths.forEach(function(filepath) { | ||
try { | ||
file = fs.readFileSync(filepath, 'utf8'); | ||
} catch (e) { | ||
file = ''; | ||
} | ||
files.push({name: filepath, contents: file}); | ||
}); | ||
return files; | ||
} | ||
module.exports.parseFromFiles = function (filepath, files, options) { | ||
@@ -158,6 +216,12 @@ return new Promise (function (resolve, reject) { | ||
options = processOptions(options, filepath); | ||
resolve(parseFromFiles(filepath, files, option)); | ||
resolve(parseFromFiles(filepath, files, options)); | ||
}); | ||
}; | ||
module.exports.parseFromFilesSync = function (filepath, files, options) { | ||
filepath = path.resolve(filepath); | ||
options = processOptions(options, filepath); | ||
return parseFromFilesSync(filepath, files, options); | ||
}; | ||
module.exports.parse = function (filepath, options) { | ||
@@ -172,1 +236,9 @@ return new Promise (function (resolve, reject) { | ||
}; | ||
module.exports.parseSync = function (filepath, options) { | ||
filepath = path.resolve(filepath); | ||
options = processOptions(options, filepath); | ||
var filepaths = getConfigFileNames(filepath, options); | ||
var files = readConfigFilesSync(filepaths); | ||
return parseFromFilesSync(filepath, files, options); | ||
}; |
{ | ||
"name": "editorconfig", | ||
"version": "0.12.2", | ||
"version": "0.13.0", | ||
"description": "EditorConfig File Locator and Interpreter for Node.js", | ||
@@ -12,3 +12,3 @@ "keywords": [ | ||
"Hong Xu (topbug.net)", | ||
"Jed Hunsaker <jed.hunsaker[at]gmail.com>", | ||
"Jed Mao (https://github.com/jedmao/)", | ||
"Trey Hunner (http://treyhunner.com)" | ||
@@ -22,5 +22,5 @@ ], | ||
"pretest": "cmake .", | ||
"test": "ctest .", | ||
"test-verbose": "ctest -VV --output-on-failure .", | ||
"codepaint": "codepainter xform -e **/**.js" | ||
"test": "npm run lint && ctest .", | ||
"test-verbose": "npm run lint && ctest -VV --output-on-failure .", | ||
"lint": "node_modules/.bin/eclint check --indent_size ignore editorconfig.js README.md \"bin/**\" \"lib/**\"" | ||
}, | ||
@@ -44,4 +44,6 @@ "repository": { | ||
"devDependencies": { | ||
"codepainter": "^0.4.4" | ||
"eclint": "^0.2.6", | ||
"mocha": "^2.3.3", | ||
"should": "^7.1.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46050
1233
3
1
0
1