How to use the editorconfig.parse function in editorconfig

To help you get started, we’ve selected a few editorconfig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gucong3000 / FELS / lib / gulp-editorconfig.js View on Github external
function fixBuffer(buf, file) {
		for (let key = 0; key < fileHeader.length; key++) {
			if (compareHeader(buf, fileHeader[key])) {
				return Promise.resolve(buf);
			}
		}

		return editorconfig.parse(file.path, options)

		.then(config => {
			file.editorconfig = config;

			// buffer转字符串
			let contents = buf.toString();

			// 替换特殊空格
			let newContents = contents.replace(/\xA0/g, " ");

			// 获取是否添加bom头的配置
			let needBom = /-bom$/i.test(config.charset);

			// 检查源代码中是否有bom头
			let hasBom = newContents.charCodeAt(0) === 0xFEFF;
github schorfES / grunt-lintspaces / tasks / lintspaces / Validator.js View on Github external
_loadSettings: function() {
			var config, key;

			// Initially the users options are the current settings:
			this._settings = merge({}, this._options);

			// Overwrite settings by .editorconfig file's settings:
			if (typeof this._settings.editorconfig === 'string') {
				if (this._grunt.file.isFile(this._settings.editorconfig)) {

					// Load config for current path
					config = editorconfig.parse(
						this._path, {
							config: this._settings.editorconfig
						}
					);

					if (typeof config === 'object') {
						// Merge editorconfig values into the correct settings names:
						for (key in config) {
							if (typeof MAPPINGS[key] === 'string') {
								switch (key) {
									case 'indent_style':
										// The 'indent_style' property value isn't
										// equal to the expected setting value:
										this._settings[MAPPINGS[key]] = config[key] + 's';
										break;
									default:
github dmnsgn / sublime-stylefmt / node_modules / stylefmt / lib / params.js View on Github external
function getEditorConfig (file) {

  var rules = {}

  function setRuleValue (ruleName, value) {
    if (value != null) {
      if (Array.isArray(rules[ruleName])) {
        rules[ruleName][0] = value
      } else {
        rules[ruleName] = [value]
      }
    }
  }

  return editorconfig.parse(file).then(function (editorconfig) {
    if (editorconfig) {
      if (editorconfig.indent_style) {
        setRuleValue('indentation', /^space$/i.test(editorconfig.indent_style) ? +editorconfig.indent_size || 2 : 'tab')
      }
      setRuleValue('no-missing-end-of-source-newline', editorconfig.insert_final_newline)
      setRuleValue('no-eol-whitespace', editorconfig.trim_trailing_whitespace)
    }
    return rules
  })
}
github jedmao / eclint / lib / eclint.ts View on Github external
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) => {
				if ((commandSettings.indent_style || fileSettings.indent_style) === 'tab') {
					fileSettings = _.omit(
						fileSettings,
						[
							'tab_width',
							'indent_size',
						],
					);
				}

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

				Object.keys(settings).forEach((setting) => {
					const rule: IDocumentRule|ILineRule = rules[setting];
github morishitter / stylefmt / lib / params.js View on Github external
function getEditorConfig (file) {

  var rules = {}

  function setRuleValue (ruleName, value) {
    if (value != null) {
      if (Array.isArray(rules[ruleName])) {
        rules[ruleName][0] = value
      } else {
        rules[ruleName] = [value]
      }
    }
  }

  return editorconfig.parse(file).then(function (editorconfig) {
    if (editorconfig) {
      if (editorconfig.indent_style) {
        setRuleValue('indentation', /^space$/i.test(editorconfig.indent_style) ? +editorconfig.indent_size || 2 : 'tab')
      }
      setRuleValue('no-missing-end-of-source-newline', editorconfig.insert_final_newline)
      setRuleValue('no-eol-whitespace', editorconfig.trim_trailing_whitespace)
    }
    return rules
  })
}
github jedmao / eclint / js / commands / check.js View on Github external
files.forEach(function (filename) {
        var settings = editorconfig.parse(filename);
        var reporter = {
            report: function (msg) {
                messages.push({
                    filename: filename,
                    msg: msg
                });
            }
        };
        var ruleNames = Object.keys(settings);
        ruleNames.forEach(function (ruleName) {
            var rule = require('../rules/' + ruleName);
            var setting = settings[ruleName];
            fs.readFile(filename, { encoding: 'utf8' }, function (err, data) {
                if (err) {
                    throw err;
                }
github jedmao / eclint / lib / eclint.ts View on Github external
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)) {
github taichi / brackets-jsbeautifier / node / EditorconfigDomain.js View on Github external
_.delay(function() {
            filepath = path.normalize(filepath);
            if (path.resolve(filepath) === filepath) {
                cb(null, editorconfig.parse(filepath, options));
            } else {
                cb("filepath must be absolute.");
            }
        });
    };