editorconfig 0.15.2 → 1.0.0

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/src/index.js DELETED
@@ -1,261 +0,0 @@
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;
@@ -1,214 +0,0 @@
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;