當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript editorconfig.parse函數代碼示例

本文整理匯總了TypeScript中editorconfig.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了parse函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: _onDidOpenDocument

	private _onDidOpenDocument(document: TextDocument) {
		if (document.isUntitled) {
			// Does not have a fs path
			return Promise.resolve();
		}
		const path = document.fileName;

		if (this._documentToConfigMap[path]) {
			applyEditorConfigToTextEditor(window.activeTextEditor, this);
			return Promise.resolve();
		}

		return editorconfig.parse(path)
			.then((config: editorconfig.knownProps) => {
				if (config.indent_size === 'tab') {
					config.indent_size = config.tab_width;
				}

				this._documentToConfigMap[path] = config;

				return applyEditorConfigToTextEditor(
					window.activeTextEditor,
					this
				);
			});
	}
開發者ID:rlugojr,項目名稱:editorconfig-vscode,代碼行數:26,代碼來源:DocumentWatcher.ts

示例2: require

	files.forEach(filename => {
		var settings = editorconfig.parse(filename);
		var reporter = {
			report: msg => {
				messages.push({
					filename: filename,
					msg: msg
				});
			}
		};

		var ruleNames = Object.keys(settings);
		ruleNames.forEach(ruleName => {
			var rule = require('../rules/' + ruleName);
			var setting = settings[ruleName];

			fs.readFile(filename, {encoding: 'utf8'}, (err, data) => {
				if (err) throw err;
				rule.check(reporter, setting, data);

				if (++count === files.length * ruleNames.length) {
					done();
				}
			});
		});
	});
開發者ID:smikes,項目名稱:eclint,代碼行數:26,代碼來源:check.ts

示例3: done

	return through.obj((file: IEditorConfigLintFile, _enc: string, done: Done) => {

		if (file.isNull()) {
			done(null, file);
			return;
		}

		if (file.isStream()) {
			done(createPluginError('Streams are not supported'));
			return;
		}

		editorconfig.parse(file.path)
			.then((fileSettings: editorconfig.KnownProps) => {
				const errors: EditorConfigError[] = [];

				const settings = getSettings(fileSettings, commandSettings);
				const document = doc.create(file.contents, settings);

				function addError(error?: EditorConfigError) {
					if (error) {
						error.fileName = file.path;
						errors.push(error);
					}
				}

				Object.keys(settings).forEach((setting) => {
					const rule: IDocumentRule|ILineRule = rules[setting];
					if (_.isUndefined(rule)) {
						return;
					}
					if (rule.type === 'DocumentRule') {
						(rule as IDocumentRule).check(settings, document).forEach(addError);
					} else {
						const checkFn = (rule as ILineRule).check;
						document.lines.forEach((line) => {
							addError(checkFn(settings, line));
						});
					}
				});

				updateResult(file, {
					config: fileSettings,
					errors,
					fixed: !!(_.get(file, 'editorconfig.fixed')),
				});

				if (options.reporter && errors.length) {
					errors.forEach(options.reporter.bind(this, file));
				}

				done(null, file);

			}).catch((err: Error) => {
				done(createPluginError(err));
			});
	});
開發者ID:jedmao,項目名稱:eclint,代碼行數:57,代碼來源:eclint.ts

示例4: extend

			fs.readFile(file, { encoding: this.options.encoding }, (err, contents) => {
				if (err) {
					this.emit('error', err);
				}
				var rawSettings = this.options.editor_config ? ec.parse(file) : {};
				rawSettings = extend(rawSettings, this.options.settings);

				var settings = this.settingFactory.createSettings(rawSettings);
				var settingProvider = new SettingProvider(rawSettings, settings);
				this.createUniqueRules(settingProvider, settings).forEach(rule => {
					callback(contents, rule);
				});
			});
開發者ID:jedmao,項目名稱:code-genie,代碼行數:13,代碼來源:genie.ts

示例5: postProcess

export function postProcess(fileName: string, formattedCode: string, opts: Options, _formatSettings: ts.FormatCodeSettings): Promise<string> {

    if (opts.verbose && opts.baseDir && !emitBaseDirWarning) {
        console.log("editorconfig is not supported baseDir options");
        emitBaseDirWarning = true;
    }

    return editorconfig
        .parse(fileName)
        .then(config => {
            if (config.insert_final_newline && !/\n$/.test(formattedCode)) {
                formattedCode += "\n";
            }
            return formattedCode;
        });
}
開發者ID:vvakame,項目名稱:typescript-formatter,代碼行數:16,代碼來源:editorconfig.ts

示例6: _onDidOpenDocument

    private _onDidOpenDocument(document: TextDocument): void {
        if (document.isUntitled) {
            // Does not have a fs path
            return;
        }

        let path = document.fileName;
        editorconfig.parse(path).then((config: editorconfig.knownProps) => {
            // workaround for the fact that sometimes indent_size is set to "tab":
            // see https://github.com/editorconfig/editorconfig-core-js/blob/b2e00d96fcf3be242d4bf748829b8e3a778fd6e2/editorconfig.js#L56
            if (config.indent_size === 'tab') {
                delete config.indent_size;
            }

            // console.log('storing ' + path + ' to ' + JSON.stringify(config, null, '\t'));
            this._documentToConfigMap[path] = config;

            applyEditorConfigToTextEditor(window.activeTextEditor, this);
        });
    }
開發者ID:asgardsinc,項目名稱:vscode-editorconfig,代碼行數:20,代碼來源:editorConfigMain.ts

示例7: makeFormatCodeOptions

export default function makeFormatCodeOptions(fileName: string, opts: Options, formatOptions: ts.FormatCodeOptions): Promise<ts.FormatCodeOptions> {
    "use strict";

    if (opts.verbose && opts.baseDir && !emitBaseDirWarning) {
        console.log("editorconfig is not supported baseDir options");
        emitBaseDirWarning = true;
    }

    return editorconfig
        .parse(fileName)
        .then(config => {
            if (Object.keys(config).length === 0) {
                return formatOptions;
            }
            if (opts.verbose) {
                console.log("editorconfig: \n" + "file: " + fileName + "\n" + JSON.stringify(config, null, 2));
            }

            if (config.indent_style === "tab") {
                formatOptions.ConvertTabsToSpaces = false;
                // if (typeof config.tab_width === "number") {
                // 	options.TabSize = config.tab_width;
                // }
            } else if (typeof config.indent_size === "number") {
                formatOptions.ConvertTabsToSpaces = true;
                formatOptions.IndentSize = config.indent_size;
            }
            if (config.end_of_line === "lf") {
                formatOptions.NewLineCharacter = "\n";
            } else if (config.end_of_line === "cr") {
                formatOptions.NewLineCharacter = "\r";
            } else if (config.end_of_line === "crlf") {
                formatOptions.NewLineCharacter = "\r\n";
            }

            return formatOptions;
        });
}
開發者ID:JoshuaKGoldberg,項目名稱:typescript-formatter,代碼行數:38,代碼來源:editorconfig.ts


注:本文中的editorconfig.parse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。