项目作者: abranhe

项目描述 :
Complex generator of .editorconfig 🐭
高级语言: JavaScript
项目地址: git://github.com/abranhe/init-editorconfig.git
创建时间: 2018-08-08T05:43:51Z
项目社区:https://github.com/abranhe/init-editorconfig

开源协议:MIT License

下载










init-editorconfig
: Complex generator of .editorconfig 🐭














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

  1. $ npm install init-editorconfig

Usage

  1. const editorconfig = require('init-editorconfig');
  2. editorconfig.root('true');
  3. editorconfig.also();
  4. editorconfig.match('*');
  5. editorconfig.property('end_of_line', 'lf');
  6. editorconfig.property('insert_final_newline', 'true');
  7. editorconfig.also();
  8. editorconfig.match('*.{js,py}');
  9. editorconfig.property('charset', 'utf-8');
  10. editorconfig.also();
  11. editorconfig.match('*.py');
  12. editorconfig.property('indent_style', 'space');
  13. editorconfig.property('indent_size', '4');
  14. editorconfig.also();
  15. editorconfig.match('Makefile');
  16. editorconfig.property('indent_style', 'tab');
  17. editorconfig.also();
  18. editorconfig.match('lib/**.js');
  19. editorconfig.property('indent_style', 'space');
  20. editorconfig.property('indent_size', '2');
  21. editorconfig.also();
  22. editorconfig.match('{package.json,.travis.yml}');
  23. editorconfig.property('indent_style', 'space');
  24. editorconfig.property('indent_size', '2');
  25. editorconfig.build();

Result in .editorconfig:

  1. # EditorConfig
  2. # https://EditorConfig.org
  3. #
  4. # Build with init-editorconfig
  5. # https://github.com/abranhe/init-editorconfig
  6. root = true
  7. [*]
  8. end_of_line = lf
  9. insert_final_newline = true
  10. [*.{js,py}]
  11. charset = utf-8
  12. [*.py]
  13. indent_style = space
  14. indent_size = 4
  15. [Makefile]
  16. indent_style = tab
  17. [lib/**.js]
  18. indent_style = space
  19. indent_size = 2
  20. [{package.json,.travis.yml}]
  21. indent_style = space
  22. indent_size = 2

getFile() Example:

  1. const editorconfig = require('init-editorconfig');
  2. editorconfig.root('true');
  3. editorconfig.also();
  4. editorconfig.match('*');
  5. editorconfig.property('end_of_line', 'lf');
  6. editorconfig.property('insert_final_newline', 'true');
  7. console.log(editorconfig.getFile());
  8. // # EditorConfig
  9. // # https://EditorConfig.org
  10. // #
  11. // # Build with init-editorconfig
  12. // # https://github.com/abranhe/init-editorconfig
  13. // root = true
  14. //
  15. // [*]
  16. // ...

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


 top ↑