本文整理汇总了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;未经允许,请勿转载。 |
请发表评论