editorconfig 0.14.1 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ ## 0.15.2
2
+ - Fix publish.
3
+
4
+ ## 0.15.1
5
+ - Update dependencies.
6
+
7
+ ## 0.15.0
8
+ - Convert source code into TypeScript. Generated type definitions are now provided.
9
+ - Remove dependency on Bluebird.
10
+ - **Breaking**: Node v4 no longer supported.
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # EditorConfig JavaScript Core
2
2
 
3
3
  [![Build Status](https://travis-ci.org/editorconfig/editorconfig-core-js.svg?branch=master)](https://travis-ci.org/editorconfig/editorconfig-core-js)
4
+ [![dependencies Status](https://david-dm.org/editorconfig/editorconfig-core-js/status.svg)](https://david-dm.org/editorconfig/editorconfig-core-js)
4
5
 
5
6
  The EditorConfig JavaScript core will provide the same functionality as the
6
7
  [EditorConfig C Core][] and [EditorConfig Python Core][].
@@ -161,10 +162,12 @@ To install dependencies for this package run this in the package directory:
161
162
  $ npm install
162
163
  ```
163
164
 
164
- Next, run:
165
+ Next, run the following commands:
165
166
 
166
167
  ```bash
167
- $ npm link
168
+ $ npm run build
169
+ $ npm run copy
170
+ $ npm link ./dist
168
171
  ```
169
172
 
170
173
  The global editorconfig will now point to the files in your development
package/bin/editorconfig CHANGED
@@ -1,42 +1,3 @@
1
1
  #!/usr/bin/env node
2
-
3
- var path = require("path");
4
- var program = require("commander");
5
- var Promise = require("bluebird");
6
-
7
- var editorconfig = require("../editorconfig");
8
- var package = require("../package.json");
9
-
10
- program.version("EditorConfig Node.js Core Version " + package.version);
11
-
12
- program
13
- .usage([
14
- "[OPTIONS] FILEPATH1 [FILEPATH2 FILEPATH3 ...]",
15
- program._version,
16
- "FILEPATH can be a hyphen (-) if you want path(s) to be read from stdin."
17
- ].join("\n\n "))
18
- .option("-f <path>", "Specify conf filename other than \".editorconfig\"")
19
- .option("-b <version>", "Specify version (used by devs to test compatibility)")
20
- .option("-v, --version", "Display version information")
21
- .parse(process.argv);
22
-
23
- // Throw away the native -V flag in lieu of the one we've manually specified
24
- // to adhere to testing requirements
25
- program.options.shift();
26
-
27
- var files = program.args;
28
-
29
- if (!files.length) {
30
- program.help();
31
- }
32
-
33
- Promise.map(files, function(filePath) {
34
- return editorconfig.parse(filePath, {config: program.F, version: program.B});
35
- }).each(function(parsed, i, length) {
36
- if (length > 1) {
37
- console.log("[%s]", files[i]);
38
- }
39
- Object.keys(parsed).forEach(function(key) {
40
- console.log(key + "=" + parsed[key]);
41
- });
42
- });
2
+ var cli = require('../src/cli')
3
+ cli.default(process.argv)
package/package.json CHANGED
@@ -1,47 +1,59 @@
1
- {
2
- "name": "editorconfig",
3
- "version": "0.14.1",
4
- "description": "EditorConfig File Locator and Interpreter for Node.js",
5
- "keywords": [
6
- "editorconfig",
7
- "core"
8
- ],
9
- "main": "editorconfig.js",
10
- "bin": {
11
- "editorconfig": "bin/editorconfig"
12
- },
13
- "contributors": [
14
- "Hong Xu (topbug.net)",
15
- "Jed Mao (https://github.com/jedmao/)",
16
- "Trey Hunner (http://treyhunner.com)"
17
- ],
18
- "directories": {
19
- "bin": "./bin",
20
- "lib": "./lib"
21
- },
22
- "scripts": {
23
- "pretest": "cmake .",
24
- "test": "npm run lint && ctest .",
25
- "test-verbose": "npm run lint && ctest -VV --output-on-failure .",
26
- "lint": "eclint check --indent_size ignore editorconfig.js README.md \"bin/**\" \"lib/**\""
27
- },
28
- "repository": {
29
- "type": "git",
30
- "url": "git://github.com/editorconfig/editorconfig-core-js.git"
31
- },
32
- "bugs": "https://github.com/editorconfig/editorconfig-core-js/issues",
33
- "author": "EditorConfig Team",
34
- "license": "MIT",
35
- "dependencies": {
36
- "bluebird": "^3.0.5",
37
- "commander": "^2.9.0",
38
- "lru-cache": "^3.2.0",
39
- "semver": "^5.1.0",
40
- "sigmund": "^1.0.1"
41
- },
42
- "devDependencies": {
43
- "eclint": "^1.1.5",
44
- "mocha": "^2.3.4",
45
- "should": "^7.1.1"
46
- }
47
- }
1
+ {
2
+ "name": "editorconfig",
3
+ "version": "0.15.2",
4
+ "description": "EditorConfig File Locator and Interpreter for Node.js",
5
+ "keywords": [
6
+ "editorconfig",
7
+ "core"
8
+ ],
9
+ "main": "src/index.js",
10
+ "contributors": [
11
+ "Hong Xu (topbug.net)",
12
+ "Jed Mao (https://github.com/jedmao/)",
13
+ "Trey Hunner (http://treyhunner.com)"
14
+ ],
15
+ "directories": {
16
+ "bin": "./bin",
17
+ "lib": "./lib"
18
+ },
19
+ "scripts": {
20
+ "clean": "rimraf dist",
21
+ "prebuild": "npm run clean",
22
+ "build": "tsc",
23
+ "pretest": "npm run lint && npm run build && npm run copy && cmake .",
24
+ "test": "ctest .",
25
+ "pretest:ci": "npm run pretest",
26
+ "test:ci": "ctest -VV --output-on-failure .",
27
+ "lint": "npm run eclint && npm run tslint",
28
+ "eclint": "eclint check --indent_size ignore \"src/**\"",
29
+ "tslint": "tslint --project tsconfig.json --exclude package.json",
30
+ "copy": "cpy .npmignore LICENSE README.md CHANGELOG.md dist && cpy bin/* dist/bin && cpy src/lib/fnmatch*.* dist/src/lib",
31
+ "prepub": "npm run lint && npm run build && npm run copy",
32
+ "pub": "npm publish ./dist"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git://github.com/editorconfig/editorconfig-core-js.git"
37
+ },
38
+ "bugs": "https://github.com/editorconfig/editorconfig-core-js/issues",
39
+ "author": "EditorConfig Team",
40
+ "license": "MIT",
41
+ "dependencies": {
42
+ "@types/node": "^10.11.7",
43
+ "@types/semver": "^5.5.0",
44
+ "commander": "^2.19.0",
45
+ "lru-cache": "^4.1.3",
46
+ "semver": "^5.6.0",
47
+ "sigmund": "^1.0.1"
48
+ },
49
+ "devDependencies": {
50
+ "@types/mocha": "^5.2.5",
51
+ "cpy-cli": "^2.0.0",
52
+ "eclint": "^2.8.0",
53
+ "mocha": "^5.2.0",
54
+ "rimraf": "^2.6.2",
55
+ "should": "^13.2.3",
56
+ "tslint": "^5.11.0",
57
+ "typescript": "^3.1.3"
58
+ }
59
+ }
package/src/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export default function cli(args: string[]): void;
package/src/cli.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var __importStar = (this && this.__importStar) || function (mod) {
6
+ if (mod && mod.__esModule) return mod;
7
+ var result = {};
8
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
9
+ result["default"] = mod;
10
+ return result;
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ // tslint:disable:no-console
14
+ var commander_1 = __importDefault(require("commander"));
15
+ var editorconfig = __importStar(require("./"));
16
+ var package_json_1 = __importDefault(require("../package.json"));
17
+ function cli(args) {
18
+ commander_1.default.version('EditorConfig Node.js Core Version ' + package_json_1.default.version);
19
+ commander_1.default
20
+ .usage([
21
+ '[OPTIONS] FILEPATH1 [FILEPATH2 FILEPATH3 ...]',
22
+ commander_1.default._version,
23
+ 'FILEPATH can be a hyphen (-) if you want path(s) to be read from stdin.',
24
+ ].join('\n\n '))
25
+ .option('-f <path>', 'Specify conf filename other than \'.editorconfig\'')
26
+ .option('-b <version>', 'Specify version (used by devs to test compatibility)')
27
+ .option('-v, --version', 'Display version information')
28
+ .parse(args);
29
+ // Throw away the native -V flag in lieu of the one we've manually specified
30
+ // to adhere to testing requirements
31
+ commander_1.default.options.shift();
32
+ var files = commander_1.default.args;
33
+ if (!files.length) {
34
+ commander_1.default.help();
35
+ }
36
+ files
37
+ .map(function (filePath) { return editorconfig.parse(filePath, {
38
+ config: commander_1.default.F,
39
+ version: commander_1.default.B,
40
+ }); })
41
+ .forEach(function (parsing, i, _a) {
42
+ var length = _a.length;
43
+ parsing.then(function (parsed) {
44
+ if (length > 1) {
45
+ console.log("[" + files[i] + "]");
46
+ }
47
+ Object.keys(parsed).forEach(function (key) {
48
+ console.log(key + "=" + parsed[key]);
49
+ });
50
+ });
51
+ });
52
+ }
53
+ exports.default = cli;
package/src/index.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ import { parseString, ParseStringResult } from './lib/ini';
3
+ export { parseString };
4
+ export interface KnownProps {
5
+ end_of_line?: 'lf' | 'crlf' | 'unset';
6
+ indent_style?: 'tab' | 'space' | 'unset';
7
+ indent_size?: number | 'tab' | 'unset';
8
+ insert_final_newline?: true | false | 'unset';
9
+ tab_width?: number | 'unset';
10
+ trim_trailing_whitespace?: true | false | 'unset';
11
+ charset?: string | 'unset';
12
+ }
13
+ export interface ECFile {
14
+ name: string;
15
+ contents: string | Buffer;
16
+ }
17
+ export interface FileConfig {
18
+ name: string;
19
+ contents: ParseStringResult;
20
+ }
21
+ export interface ParseOptions {
22
+ config?: string;
23
+ version?: string;
24
+ root?: string;
25
+ }
26
+ export declare function parseFromFiles(filepath: string, files: Promise<ECFile[]>, options?: ParseOptions): Promise<KnownProps>;
27
+ export declare function parseFromFilesSync(filepath: string, files: ECFile[], options?: ParseOptions): KnownProps;
28
+ export declare function parse(_filepath: string, _options?: ParseOptions): Promise<KnownProps>;
29
+ export declare function parseSync(_filepath: string, _options?: ParseOptions): KnownProps;
package/src/index.js ADDED
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __importStar = (this && this.__importStar) || function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
41
+ result["default"] = mod;
42
+ return result;
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ var fs = __importStar(require("fs"));
49
+ var path = __importStar(require("path"));
50
+ var semver = __importStar(require("semver"));
51
+ var fnmatch_1 = __importDefault(require("./lib/fnmatch"));
52
+ var ini_1 = require("./lib/ini");
53
+ exports.parseString = ini_1.parseString;
54
+ var package_json_1 = __importDefault(require("../package.json"));
55
+ var knownProps = {
56
+ end_of_line: true,
57
+ indent_style: true,
58
+ indent_size: true,
59
+ insert_final_newline: true,
60
+ trim_trailing_whitespace: true,
61
+ charset: true,
62
+ };
63
+ function fnmatch(filepath, glob) {
64
+ var matchOptions = { matchBase: true, dot: true, noext: true };
65
+ glob = glob.replace(/\*\*/g, '{*,**/**/**}');
66
+ return fnmatch_1.default(filepath, glob, matchOptions);
67
+ }
68
+ function getConfigFileNames(filepath, options) {
69
+ var paths = [];
70
+ do {
71
+ filepath = path.dirname(filepath);
72
+ paths.push(path.join(filepath, options.config));
73
+ } while (filepath !== options.root);
74
+ return paths;
75
+ }
76
+ function processMatches(matches, version) {
77
+ // Set indent_size to 'tab' if indent_size is unspecified and
78
+ // indent_style is set to 'tab'.
79
+ if ('indent_style' in matches
80
+ && matches.indent_style === 'tab'
81
+ && !('indent_size' in matches)
82
+ && semver.gte(version, '0.10.0')) {
83
+ matches.indent_size = 'tab';
84
+ }
85
+ // Set tab_width to indent_size if indent_size is specified and
86
+ // tab_width is unspecified
87
+ if ('indent_size' in matches
88
+ && !('tab_width' in matches)
89
+ && matches.indent_size !== 'tab') {
90
+ matches.tab_width = matches.indent_size;
91
+ }
92
+ // Set indent_size to tab_width if indent_size is 'tab'
93
+ if ('indent_size' in matches
94
+ && 'tab_width' in matches
95
+ && matches.indent_size === 'tab') {
96
+ matches.indent_size = matches.tab_width;
97
+ }
98
+ return matches;
99
+ }
100
+ function processOptions(options, filepath) {
101
+ if (options === void 0) { options = {}; }
102
+ return {
103
+ config: options.config || '.editorconfig',
104
+ version: options.version || package_json_1.default.version,
105
+ root: path.resolve(options.root || path.parse(filepath).root),
106
+ };
107
+ }
108
+ function buildFullGlob(pathPrefix, glob) {
109
+ switch (glob.indexOf('/')) {
110
+ case -1:
111
+ glob = '**/' + glob;
112
+ break;
113
+ case 0:
114
+ glob = glob.substring(1);
115
+ break;
116
+ default:
117
+ break;
118
+ }
119
+ return path.join(pathPrefix, glob);
120
+ }
121
+ function extendProps(props, options) {
122
+ if (props === void 0) { props = {}; }
123
+ if (options === void 0) { options = {}; }
124
+ for (var key in options) {
125
+ if (options.hasOwnProperty(key)) {
126
+ var value = options[key];
127
+ var key2 = key.toLowerCase();
128
+ var value2 = value;
129
+ if (knownProps[key2]) {
130
+ value2 = value.toLowerCase();
131
+ }
132
+ try {
133
+ value2 = JSON.parse(value);
134
+ }
135
+ catch (e) { }
136
+ if (typeof value === 'undefined' || value === null) {
137
+ // null and undefined are values specific to JSON (no special meaning
138
+ // in editorconfig) & should just be returned as regular strings.
139
+ value2 = String(value);
140
+ }
141
+ props[key2] = value2;
142
+ }
143
+ }
144
+ return props;
145
+ }
146
+ function parseFromConfigs(configs, filepath, options) {
147
+ return processMatches(configs
148
+ .reverse()
149
+ .reduce(function (matches, file) {
150
+ var pathPrefix = path.dirname(file.name);
151
+ file.contents.forEach(function (section) {
152
+ var glob = section[0];
153
+ var options2 = section[1];
154
+ if (!glob) {
155
+ return;
156
+ }
157
+ var fullGlob = buildFullGlob(pathPrefix, glob);
158
+ if (!fnmatch(filepath, fullGlob)) {
159
+ return;
160
+ }
161
+ matches = extendProps(matches, options2);
162
+ });
163
+ return matches;
164
+ }, {}), options.version);
165
+ }
166
+ function getConfigsForFiles(files) {
167
+ var configs = [];
168
+ for (var i in files) {
169
+ if (files.hasOwnProperty(i)) {
170
+ var file = files[i];
171
+ var contents = ini_1.parseString(file.contents);
172
+ configs.push({
173
+ name: file.name,
174
+ contents: contents,
175
+ });
176
+ if ((contents[0][1].root || '').toLowerCase() === 'true') {
177
+ break;
178
+ }
179
+ }
180
+ }
181
+ return configs;
182
+ }
183
+ function readConfigFiles(filepaths) {
184
+ return __awaiter(this, void 0, void 0, function () {
185
+ return __generator(this, function (_a) {
186
+ return [2 /*return*/, Promise.all(filepaths.map(function (name) { return new Promise(function (resolve) {
187
+ fs.readFile(name, 'utf8', function (err, data) {
188
+ resolve({
189
+ name: name,
190
+ contents: err ? '' : data,
191
+ });
192
+ });
193
+ }); }))];
194
+ });
195
+ });
196
+ }
197
+ function readConfigFilesSync(filepaths) {
198
+ var files = [];
199
+ var file;
200
+ filepaths.forEach(function (filepath) {
201
+ try {
202
+ file = fs.readFileSync(filepath, 'utf8');
203
+ }
204
+ catch (e) {
205
+ file = '';
206
+ }
207
+ files.push({
208
+ name: filepath,
209
+ contents: file,
210
+ });
211
+ });
212
+ return files;
213
+ }
214
+ function opts(filepath, options) {
215
+ if (options === void 0) { options = {}; }
216
+ var resolvedFilePath = path.resolve(filepath);
217
+ return [
218
+ resolvedFilePath,
219
+ processOptions(options, resolvedFilePath),
220
+ ];
221
+ }
222
+ function parseFromFiles(filepath, files, options) {
223
+ if (options === void 0) { options = {}; }
224
+ return __awaiter(this, void 0, void 0, function () {
225
+ var _a, resolvedFilePath, processedOptions;
226
+ return __generator(this, function (_b) {
227
+ _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
228
+ return [2 /*return*/, files.then(getConfigsForFiles)
229
+ .then(function (configs) { return parseFromConfigs(configs, resolvedFilePath, processedOptions); })];
230
+ });
231
+ });
232
+ }
233
+ exports.parseFromFiles = parseFromFiles;
234
+ function parseFromFilesSync(filepath, files, options) {
235
+ if (options === void 0) { options = {}; }
236
+ var _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
237
+ return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
238
+ }
239
+ exports.parseFromFilesSync = parseFromFilesSync;
240
+ function parse(_filepath, _options) {
241
+ if (_options === void 0) { _options = {}; }
242
+ return __awaiter(this, void 0, void 0, function () {
243
+ var _a, resolvedFilePath, processedOptions, filepaths;
244
+ return __generator(this, function (_b) {
245
+ _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
246
+ filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
247
+ return [2 /*return*/, readConfigFiles(filepaths)
248
+ .then(getConfigsForFiles)
249
+ .then(function (configs) { return parseFromConfigs(configs, resolvedFilePath, processedOptions); })];
250
+ });
251
+ });
252
+ }
253
+ exports.parse = parse;
254
+ function parseSync(_filepath, _options) {
255
+ if (_options === void 0) { _options = {}; }
256
+ var _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
257
+ var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
258
+ var files = readConfigFilesSync(filepaths);
259
+ return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
260
+ }
261
+ exports.parseSync = parseSync;
@@ -0,0 +1,214 @@
1
+ // Type definitions for Minimatch 3.0
2
+ // Project: https://github.com/isaacs/minimatch
3
+ // Definitions by: vvakame <https://github.com/vvakame>
4
+ // Shant Marouti <https://github.com/shantmarouti>
5
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
+
7
+ /**
8
+ * Tests a path against the pattern using the options.
9
+ */
10
+ declare function M(target: string, pattern: string, options?: M.IOptions): boolean;
11
+
12
+ declare namespace M {
13
+ /**
14
+ * Match against the list of files, in the style of fnmatch or glob.
15
+ * If nothing is matched, and options.nonull is set,
16
+ * then return a list containing the pattern itself.
17
+ */
18
+ function match(list: string[], pattern: string, options?: IOptions): string[];
19
+
20
+ /**
21
+ * Returns a function that tests its supplied argument, suitable for use with Array.filter
22
+ */
23
+ function filter(pattern: string, options?: IOptions): (element: string, indexed: number, array: string[]) => boolean;
24
+
25
+ /**
26
+ * Make a regular expression object from the pattern.
27
+ */
28
+ function makeRe(pattern: string, options?: IOptions): RegExp;
29
+
30
+ var Minimatch: IMinimatchStatic;
31
+
32
+ interface IOptions {
33
+ /**
34
+ * Dump a ton of stuff to stderr.
35
+ *
36
+ * @default false
37
+ */
38
+ debug?: boolean;
39
+
40
+ /**
41
+ * Do not expand {a,b} and {1..3} brace sets.
42
+ *
43
+ * @default false
44
+ */
45
+ nobrace?: boolean;
46
+
47
+ /**
48
+ * Disable ** matching against multiple folder names.
49
+ *
50
+ * @default false
51
+ */
52
+ noglobstar?: boolean;
53
+
54
+ /**
55
+ * Allow patterns to match filenames starting with a period,
56
+ * even if the pattern does not explicitly have a period in that spot.
57
+ *
58
+ * @default false
59
+ */
60
+ dot?: boolean;
61
+
62
+ /**
63
+ * Disable "extglob" style patterns like +(a|b).
64
+ *
65
+ * @default false
66
+ */
67
+ noext?: boolean;
68
+
69
+ /**
70
+ * Perform a case-insensitive match.
71
+ *
72
+ * @default false
73
+ */
74
+ nocase?: boolean;
75
+
76
+ /**
77
+ * When a match is not found by minimatch.match,
78
+ * return a list containing the pattern itself if this option is set.
79
+ * Otherwise, an empty list is returned if there are no matches.
80
+ *
81
+ * @default false
82
+ */
83
+ nonull?: boolean;
84
+
85
+ /**
86
+ * If set, then patterns without slashes will be matched against
87
+ * the basename of the path if it contains slashes.
88
+ *
89
+ * @default false
90
+ */
91
+ matchBase?: boolean;
92
+
93
+ /**
94
+ * Suppress the behavior of treating #
95
+ * at the start of a pattern as a comment.
96
+ *
97
+ * @default false
98
+ */
99
+ nocomment?: boolean;
100
+
101
+ /**
102
+ * Suppress the behavior of treating a leading ! character as negation.
103
+ *
104
+ * @default false
105
+ */
106
+ nonegate?: boolean;
107
+
108
+ /**
109
+ * Returns from negate expressions the same as if they were not negated.
110
+ * (Ie, true on a hit, false on a miss.)
111
+ *
112
+ * @default false
113
+ */
114
+ flipNegate?: boolean;
115
+ }
116
+
117
+ interface IMinimatchStatic {
118
+ new(pattern: string, options?: IOptions): IMinimatch;
119
+ prototype: IMinimatch;
120
+ }
121
+
122
+ interface IMinimatch {
123
+ /**
124
+ * The original pattern the minimatch object represents.
125
+ */
126
+ pattern: string;
127
+
128
+ /**
129
+ * The options supplied to the constructor.
130
+ */
131
+ options: IOptions;
132
+
133
+ /**
134
+ * A 2-dimensional array of regexp or string expressions.
135
+ */
136
+ set: any[][]; // (RegExp | string)[][]
137
+
138
+ /**
139
+ * A single regular expression expressing the entire pattern.
140
+ * Created by the makeRe method.
141
+ */
142
+ regexp: RegExp;
143
+
144
+ /**
145
+ * True if the pattern is negated.
146
+ */
147
+ negate: boolean;
148
+
149
+ /**
150
+ * True if the pattern is a comment.
151
+ */
152
+ comment: boolean;
153
+
154
+ /**
155
+ * True if the pattern is ""
156
+ */
157
+ empty: boolean;
158
+
159
+ /**
160
+ * Generate the regexp member if necessary, and return it.
161
+ * Will return false if the pattern is invalid.
162
+ */
163
+ makeRe(): RegExp; // regexp or boolean
164
+
165
+ /**
166
+ * Return true if the filename matches the pattern, or false otherwise.
167
+ */
168
+ match(fname: string): boolean;
169
+
170
+ /**
171
+ * Take a /-split filename, and match it against a single row in the regExpSet.
172
+ * This method is mainly for internal use, but is exposed so that it can be used
173
+ * by a glob-walker that needs to avoid excessive filesystem calls.
174
+ */
175
+ matchOne(files: string[], pattern: string[], partial: boolean): boolean;
176
+
177
+ /**
178
+ * Deprecated. For internal use.
179
+ *
180
+ * @private
181
+ */
182
+ debug(): void;
183
+
184
+ /**
185
+ * Deprecated. For internal use.
186
+ *
187
+ * @private
188
+ */
189
+ make(): void;
190
+
191
+ /**
192
+ * Deprecated. For internal use.
193
+ *
194
+ * @private
195
+ */
196
+ parseNegate(): void;
197
+
198
+ /**
199
+ * Deprecated. For internal use.
200
+ *
201
+ * @private
202
+ */
203
+ braceExpand(pattern: string, options: IOptions): void;
204
+
205
+ /**
206
+ * Deprecated. For internal use.
207
+ *
208
+ * @private
209
+ */
210
+ parse(pattern: string, isSub?: boolean): void;
211
+ }
212
+ }
213
+
214
+ export = M;
@@ -1,37 +1,10 @@
1
1
  // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>
2
2
 
3
- ;(function (require, exports, module, platform) {
3
+ var platform = typeof process === "object" ? process.platform : "win32"
4
4
 
5
5
  if (module) module.exports = minimatch
6
6
  else exports.minimatch = minimatch
7
7
 
8
- if (!require) {
9
- require = function (id) {
10
- switch (id) {
11
- case "sigmund": return function sigmund (obj) {
12
- return JSON.stringify(obj)
13
- }
14
- case "path": return { basename: function (f) {
15
- f = f.split(/[\/\\]/)
16
- var e = f.pop()
17
- if (!e) e = f.pop()
18
- return e
19
- }}
20
- case "lru-cache": return function LRUCache () {
21
- // not quite an LRU, but still space-limited.
22
- var cache = {}
23
- var cnt = 0
24
- this.set = function (k, v) {
25
- cnt ++
26
- if (cnt >= 100) cache = {}
27
- cache[k] = v
28
- }
29
- this.get = function (k) { return cache[k] }
30
- }
31
- }
32
- }
33
- }
34
-
35
8
  minimatch.Minimatch = Minimatch
36
9
 
37
10
  var LRU = require("lru-cache")
@@ -1072,9 +1045,3 @@
1072
1045
  function regExpEscape (s) {
1073
1046
  return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
1074
1047
  }
1075
-
1076
- })( typeof require === "function" ? require : null,
1077
- this,
1078
- typeof module === "object" ? module : null,
1079
- typeof process === "object" ? process.platform : "win32"
1080
- )
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { URL } from 'url';
3
+ /**
4
+ * Parses an .ini file
5
+ * @param file The location of the .ini file
6
+ */
7
+ export declare function parse(file: string | number | Buffer | URL): Promise<[string | null, SectionBody][]>;
8
+ export declare function parseSync(file: string | number | Buffer | URL): [string | null, SectionBody][];
9
+ export declare type SectionName = string | null;
10
+ export interface SectionBody {
11
+ [key: string]: string;
12
+ }
13
+ export declare type ParseStringResult = Array<[SectionName, SectionBody]>;
14
+ export declare function parseString(data: string): ParseStringResult;
package/src/lib/ini.js ADDED
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ // Based on iniparser by shockie <https://npmjs.org/package/iniparser>
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importStar = (this && this.__importStar) || function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
42
+ result["default"] = mod;
43
+ return result;
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ var fs = __importStar(require("fs"));
47
+ /**
48
+ * define the possible values:
49
+ * section: [section]
50
+ * param: key=value
51
+ * comment: ;this is a comment
52
+ */
53
+ var regex = {
54
+ section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
55
+ param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
56
+ comment: /^\s*[#;].*$/,
57
+ };
58
+ /**
59
+ * Parses an .ini file
60
+ * @param file The location of the .ini file
61
+ */
62
+ function parse(file) {
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ return __generator(this, function (_a) {
65
+ return [2 /*return*/, new Promise(function (resolve, reject) {
66
+ fs.readFile(file, 'utf8', function (err, data) {
67
+ if (err) {
68
+ reject(err);
69
+ return;
70
+ }
71
+ resolve(parseString(data));
72
+ });
73
+ })];
74
+ });
75
+ });
76
+ }
77
+ exports.parse = parse;
78
+ function parseSync(file) {
79
+ return parseString(fs.readFileSync(file, 'utf8'));
80
+ }
81
+ exports.parseSync = parseSync;
82
+ function parseString(data) {
83
+ var sectionBody = {};
84
+ var sectionName = null;
85
+ var value = [[sectionName, sectionBody]];
86
+ var lines = data.split(/\r\n|\r|\n/);
87
+ lines.forEach(function (line) {
88
+ var match;
89
+ if (regex.comment.test(line)) {
90
+ return;
91
+ }
92
+ if (regex.param.test(line)) {
93
+ match = line.match(regex.param);
94
+ sectionBody[match[1]] =
95
+ match[2];
96
+ }
97
+ else if (regex.section.test(line)) {
98
+ match = line.match(regex.section);
99
+ sectionName = match[1];
100
+ sectionBody = {};
101
+ value.push([sectionName, sectionBody]);
102
+ }
103
+ });
104
+ return value;
105
+ }
106
+ exports.parseString = parseString;
package/.gitmodules DELETED
@@ -1,3 +0,0 @@
1
- [submodule "tests"]
2
- path = tests
3
- url = git://github.com/editorconfig/editorconfig-core-test.git
package/editorconfig.js DELETED
@@ -1,239 +0,0 @@
1
- var Promise = require('bluebird');
2
- var fs = require('fs');
3
- var os = require('os');
4
- var path = require('path');
5
- var semver = require('semver');
6
- var util = require('util');
7
- var whenReadFile = Promise.promisify(fs.readFile);
8
-
9
- var iniparser = require('./lib/ini');
10
- var minimatch = require('./lib/fnmatch');
11
- var pkg = require('./package.json');
12
-
13
- var knownProps = [
14
- 'end_of_line',
15
- 'indent_style',
16
- 'indent_size',
17
- 'insert_final_newline',
18
- 'trim_trailing_whitespace',
19
- 'charset'
20
- ].reduce(function (set, prop) {
21
- set[prop] = true;
22
- return set;
23
- }, {});
24
-
25
- function fnmatch(filepath, glob) {
26
- var matchOptions = {matchBase: true, dot: true, noext: true};
27
- glob = glob.replace(/\*\*/g, '{*,**/**/**}');
28
- return minimatch(filepath, glob, matchOptions);
29
- }
30
-
31
- function getConfigFileNames(filepath, options) {
32
- var paths = [];
33
- do {
34
- filepath = path.dirname(filepath);
35
- paths.push(path.join(filepath, options.config));
36
- } while (filepath !== options.root);
37
- return paths;
38
- }
39
-
40
- function getFilepathRoot(filepath) {
41
- if (path.parse !== undefined) {
42
- // Node.js >= 0.11.15
43
- return path.parse(filepath).root;
44
- }
45
- if (os.platform() === 'win32') {
46
- return path.resolve(filepath).match(/^(\\\\[^\\]+\\)?[^\\]+\\/)[0];
47
- }
48
- return '/';
49
- }
50
-
51
- function processMatches(matches, version) {
52
- // Set indent_size to "tab" if indent_size is unspecified and
53
- // indent_style is set to "tab".
54
- if ("indent_style" in matches && matches.indent_style === "tab" &&
55
- !("indent_size" in matches) && semver.gte(version, "0.10.0")) {
56
- matches.indent_size = "tab";
57
- }
58
-
59
- // Set tab_width to indent_size if indent_size is specified and
60
- // tab_width is unspecified
61
- if ("indent_size" in matches && !("tab_width" in matches) &&
62
- matches.indent_size !== "tab")
63
- matches.tab_width = matches.indent_size;
64
-
65
- // Set indent_size to tab_width if indent_size is "tab"
66
- if("indent_size" in matches && "tab_width" in matches &&
67
- matches.indent_size === "tab")
68
- matches.indent_size = matches.tab_width;
69
-
70
- return matches;
71
- }
72
-
73
- function processOptions(options, filepath) {
74
- options = options || {};
75
- return {
76
- config: options.config || '.editorconfig',
77
- version: options.version || pkg.version,
78
- root: path.resolve(options.root || getFilepathRoot(filepath))
79
- };
80
- }
81
-
82
- function buildFullGlob(pathPrefix, glob) {
83
- switch (glob.indexOf('/')) {
84
- case -1: glob = "**/" + glob; break;
85
- case 0: glob = glob.substring(1); break;
86
- }
87
- return path.join(pathPrefix, glob);
88
- }
89
-
90
- function extendProps(props, options) {
91
- for (var key in options) {
92
- var value = options[key];
93
- key = key.toLowerCase();
94
- if (knownProps[key]) {
95
- value = value.toLowerCase();
96
- }
97
- try {
98
- value = JSON.parse(value);
99
- } catch(e) {}
100
- if (typeof value === 'undefined' || value === null) {
101
- // null and undefined are values specific to JSON (no special meaning
102
- // in editorconfig) & should just be returned as regular strings.
103
- value = String(value);
104
- }
105
- props[key] = value;
106
- }
107
- return props;
108
- }
109
-
110
- function parseFromFiles(filepath, files, options) {
111
- return getConfigsForFiles(files).then(function (configs) {
112
- return configs.reverse();
113
- }).reduce(function (matches, file) {
114
- var pathPrefix = path.dirname(file.name);
115
- file.contents.forEach(function (section) {
116
- var glob = section[0], options = section[1];
117
- if (!glob) return;
118
- var fullGlob = buildFullGlob(pathPrefix, glob);
119
- if (!fnmatch(filepath, fullGlob)) return;
120
- matches = extendProps(matches, options);
121
- });
122
- return matches;
123
- }, {}).then(function (matches) {
124
- return processMatches(matches, options.version);
125
- });
126
- }
127
-
128
- function parseFromFilesSync(filepath, files, options) {
129
- var configs = getConfigsForFilesSync(files);
130
- configs.reverse();
131
- var matches = {};
132
- configs.forEach(function(config) {
133
- var pathPrefix = path.dirname(config.name);
134
- config.contents.forEach(function(section) {
135
- var glob = section[0], options = section[1];
136
- if (!glob) return;
137
- var fullGlob = buildFullGlob(pathPrefix, glob);
138
- if (!fnmatch(filepath, fullGlob)) return;
139
- matches = extendProps(matches, options);
140
- });
141
- });
142
- return processMatches(matches, options.version);
143
- }
144
-
145
- function StopReduce(array) {
146
- this.array = array;
147
- }
148
-
149
- StopReduce.prototype = Object.create(Error.prototype);
150
-
151
- function getConfigsForFiles(files) {
152
- return Promise.reduce(files, function (configs, file) {
153
- var contents = iniparser.parseString(file.contents);
154
- configs.push({
155
- name: file.name,
156
- contents: contents
157
- });
158
- if ((contents[0][1].root || '').toLowerCase() === 'true') {
159
- return Promise.reject(new StopReduce(configs));
160
- }
161
- return configs;
162
- }, []).catch(StopReduce, function (stop) {
163
- return stop.array;
164
- });
165
- }
166
-
167
- function getConfigsForFilesSync(files) {
168
- var configs = [];
169
- for (var i in files) {
170
- var file = files[i];
171
- var contents = iniparser.parseString(file.contents);
172
- configs.push({
173
- name: file.name,
174
- contents: contents
175
- });
176
- if ((contents[0][1].root || '').toLowerCase() === 'true') {
177
- break;
178
- }
179
- };
180
- return configs;
181
- }
182
-
183
- function readConfigFiles(filepaths) {
184
- return Promise.map(filepaths, function (path) {
185
- return whenReadFile(path, 'utf-8').catch(function () {
186
- return '';
187
- }).then(function (contents) {
188
- return {name: path, contents: contents};
189
- });
190
- });
191
- }
192
-
193
- function readConfigFilesSync(filepaths) {
194
- var files = [];
195
- var file;
196
- filepaths.forEach(function(filepath) {
197
- try {
198
- file = fs.readFileSync(filepath, 'utf8');
199
- } catch (e) {
200
- file = '';
201
- }
202
- files.push({name: filepath, contents: file});
203
- });
204
- return files;
205
- }
206
-
207
- module.exports.parseFromFiles = function (filepath, files, options) {
208
- return new Promise (function (resolve, reject) {
209
- filepath = path.resolve(filepath);
210
- options = processOptions(options, filepath);
211
- resolve(parseFromFiles(filepath, files, options));
212
- });
213
- };
214
-
215
- module.exports.parseFromFilesSync = function (filepath, files, options) {
216
- filepath = path.resolve(filepath);
217
- options = processOptions(options, filepath);
218
- return parseFromFilesSync(filepath, files, options);
219
- };
220
-
221
- module.exports.parse = function (filepath, options) {
222
- return new Promise (function (resolve, reject) {
223
- filepath = path.resolve(filepath);
224
- options = processOptions(options, filepath);
225
- var filepaths = getConfigFileNames(filepath, options);
226
- var files = readConfigFiles(filepaths);
227
- resolve(parseFromFiles(filepath, files, options));
228
- });
229
- };
230
-
231
- module.exports.parseSync = function (filepath, options) {
232
- filepath = path.resolve(filepath);
233
- options = processOptions(options, filepath);
234
- var filepaths = getConfigFileNames(filepath, options);
235
- var files = readConfigFilesSync(filepaths);
236
- return parseFromFilesSync(filepath, files, options);
237
- };
238
-
239
- module.exports.parseString = iniparser.parseString;
package/lib/ini.js DELETED
@@ -1,63 +0,0 @@
1
- // Based on iniparser by shockie <https://npmjs.org/package/iniparser>
2
-
3
- /*
4
- * get the file handler
5
- */
6
- var fs = require('fs');
7
-
8
- /*
9
- * define the possible values:
10
- * section: [section]
11
- * param: key=value
12
- * comment: ;this is a comment
13
- */
14
- var regex = {
15
- section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
16
- param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
17
- comment: /^\s*[#;].*$/
18
- };
19
-
20
- /*
21
- * parses a .ini file
22
- * @param: {String} file, the location of the .ini file
23
- * @param: {Function} callback, the function that will be called when parsing is done
24
- * @return: none
25
- */
26
- exports.parse = function (file, callback) {
27
- if (!callback) {
28
- return;
29
- }
30
- fs.readFile(file, 'utf8', function (err, data) {
31
- if (err) {
32
- callback(err);
33
- } else {
34
- callback(null, parse(data));
35
- }
36
- });
37
- };
38
-
39
- exports.parseSync = function (file) {
40
- return parse(fs.readFileSync(file, 'utf8'));
41
- };
42
-
43
- exports.parseString = function (data) {
44
- var sectionBody = {};
45
- var sectionName = null;
46
- var value = [[sectionName, sectionBody]];
47
- var lines = data.split(/\r\n|\r|\n/);
48
- lines.forEach(function (line) {
49
- var match;
50
- if (regex.comment.test(line)) {
51
- return;
52
- } else if (regex.param.test(line)) {
53
- match = line.match(regex.param);
54
- sectionBody[match[1]] = match[2];
55
- } else if (regex.section.test(line)) {
56
- match = line.match(regex.section);
57
- sectionName = match[1];
58
- sectionBody = {};
59
- value.push([sectionName, sectionBody]);
60
- }
61
- });
62
- return value;
63
- };