How to use editorconfig - 10 common examples

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 gitlabhq / gitlabhq / app / assets / javascripts / ide / lib / editorconfig / parser.js View on Github external
function getRulesWithConfigs(filePath, configFiles = [], rules = {}) {
  if (!configFiles.length) return rules;

  const [{ content, path: configPath }, ...nextConfigs] = configFiles;
  const configDir = dirname(configPath);

  if (!filePath.startsWith(configDir)) return rules;

  const parsed = parseString(content);
  const isRoot = isRootConfig(parsed);
  const relativeFilePath = filePath.slice(configDir.length);

  const sectionRules = parsed.reduce(
    (acc, section) => Object.assign(acc, getRulesForSection(relativeFilePath, section)),
    {},
  );

  // prefer existing rules by overwriting to section rules
  const result = Object.assign(sectionRules, rules);

  return isRoot ? result : getRulesWithConfigs(filePath, nextConfigs, result);
}
github marko-js / marko-prettyprint / src / util / readConfigFile.js View on Github external
}

    if (currentDir === rootDir) {
      // Don't go up past the package's root directory
      break;
    }

    var parentDir = path.dirname(currentDir);
    if (!parentDir || parentDir === currentDir) {
      break;
    }
    currentDir = parentDir;
  }

  if (editorConfigs) {
    var parsedEditorConfig = editorconfig.parseFromFilesSync(
      filename,
      editorConfigs
    );
    var convertedEditorConfig = convertEditorConfig(parsedEditorConfig);
    mergeOptions(convertedEditorConfig);
  }

  if (!config.eol) {
    config.eol = os.EOL;
  }

  return config;
}
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 thorn0 / organize-imports-cli / cli.js View on Github external
for (const filePath of filePaths) {
    const tsConfigFilePath = tsconfig.findSync(path.dirname(filePath));
    const projectEntry = tsConfigFilePath && projects[tsConfigFilePath];

    if (projectEntry) {
      const sourceFile = projectEntry.project.getSourceFile(filePath);

      if (sourceFile) {
        if (projectEntry.files !== "all") {
          projectEntry.files.push(sourceFile);
        }
        continue;
      }
    }

    const ec = editorconfig.parseSync(filePath);
    const manipulationSettings = getManipulationSettings(ec);
    const detectNewLineKind = !!ec.end_of_line;

    if (tsConfigFilePath && !projectEntry) {
      const project = new Project({ tsConfigFilePath, manipulationSettings });

      if (path.basename(filePath).toLowerCase() === "tsconfig.json") {
        projects[tsConfigFilePath] = {
          files: "all",
          project,
          detectNewLineKind
        };
        continue;
      }

      const sourceFile = project.getSourceFile(filePath);
github hawtio / hawtio-ui / node_modules / js-beautify / js / lib / cli.js View on Github external
function set_file_editorconfig_opts(file, config) {
    try {
        var eConfigs = editorconfig.parseSync(file);

        if (eConfigs.indent_style === "tab") {
            config.indent_with_tabs = true;
        } else if (eConfigs.indent_style === "space") {
            config.indent_with_tabs = false;
        }

        if (eConfigs.indent_size) {
            config.indent_size = eConfigs.indent_size;
        }

        if (eConfigs.max_line_length) {
            if (eConfigs.max_line_length === "off") {
                config.wrap_line_length = 0;
            } else {
                config.wrap_line_length = parseInt(eConfigs.max_line_length);