2.0.0 β€’ Published 6 years ago

init-editorconfig v2.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

See

Overview

EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles. EditorConfig files are easily readable and they work nicely with version control systems.

Read more about at EditorConfig.org

Universal Properties

indent_style

Indentation Style

The values are case insensitive. They will be lowercased by the core library.

Possible Values

  • tab
  • space

indent_size

Indentation Size (in single-spaced characters)

The values are case insensitive. They will be lowercased by the core library.

Possible Values

  • an integer
  • tab

If indent_size equals to tab, the indent_size will be set to the tab size, which should be tab_width if tab_width is specified, or the tab size set by editor if tab_width is not specified.

tab_width

Width of a single tabstop character

Possible Values

  • a positive integer (defaults indent_size when indent_size is a number)

end_of_line

Line ending file format (Unix, DOS, Mac)

Possible Values

  • lf
  • crlf
  • cr

charset

File character encoding

The values are case insensitive. They will be lowercased by the core library.

Possible Values

  • latin1
  • utf-8
  • utf-16be
  • utf-16le
  • utf-8-bom

trim_trailing_whitespace

Denotes whether whitespace is allowed at the end of lines

The values are case insensitive. They will be lowercased by the core library.

Possible Values

  • true
  • false

insert_final_newline

Denotes whether file should end with a newline

The values are case insensitive. They will be lowercased by the core library.

Possible Values

  • true
  • false

max_line_length

Forces hard line wrapping after the amount of characters specified. off to turn off this feature (use the editor settings).

Possible Values

  • positive integers
  • off

Install

$ npm install init-editorconfig

Usage

const editorconfig = require('init-editorconfig');

editorconfig.root('true');

editorconfig.also();
editorconfig.match('*');
editorconfig.property('end_of_line', 'lf');
editorconfig.property('insert_final_newline', 'true');

editorconfig.also();
editorconfig.match('*.{js,py}');
editorconfig.property('charset', 'utf-8');

editorconfig.also();
editorconfig.match('*.py');
editorconfig.property('indent_style', 'space');
editorconfig.property('indent_size', '4');

editorconfig.also();
editorconfig.match('Makefile');
editorconfig.property('indent_style', 'tab');

editorconfig.also();
editorconfig.match('lib/**.js');
editorconfig.property('indent_style', 'space');
editorconfig.property('indent_size', '2');

editorconfig.also();
editorconfig.match('{package.json,.travis.yml}');
editorconfig.property('indent_style', 'space');
editorconfig.property('indent_size', '2');

editorconfig.build();

Result in .editorconfig:

# EditorConfig
# https://EditorConfig.org
#
# Build with init-editorconfig
# https://github.com/abranhe/init-editorconfig
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,py}]
charset = utf-8

[*.py]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

[lib/**.js]
indent_style = space
indent_size = 2

[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

getFile() Example:

const editorconfig = require('init-editorconfig');

editorconfig.root('true');

editorconfig.also();
editorconfig.match('*');
editorconfig.property('end_of_line', 'lf');
editorconfig.property('insert_final_newline', 'true');

console.log(editorconfig.getFile());
// # EditorConfig
// # https://EditorConfig.org
// #
// # Build with init-editorconfig
// # https://github.com/abranhe/init-editorconfig
// root = true
//
// [*]
// ...

API

root(bool)

Special property that should be specified at the top of the file outside of any sections. Set to true to stop .editorconfig files search on current file.

also()

Add some spaces to include other Properties

match(WildcardPatterns)

Set special characters to be recognized for EditorConfig

property(property, value)

Create a new property for EditorConfig

build()

Create a new .gitignore file on the current directory

getFile()

Get an string with the file created values

Related

Team

Carlos Abraham Logo
Carlos Abraham

License

MIT License Β© Carlos Abraham