本文整理汇总了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
);
});
}
示例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();
}
});
});
});
示例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));
});
});
示例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);
});
});
示例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;
});
}
示例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);
});
}
示例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;
});
}