init-editorconfig
: Complex generator of .editorconfig π
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
Indentation Style
The values are case insensitive. They will be lowercased by the core library.
Possible Values
tab
space
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.
Width of a single tabstop character
Possible Values
- a positive integer (defaults
indent_size
whenindent_size
is a number)
Line ending file format (Unix, DOS, Mac)
Possible Values
lf
crlf
cr
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
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
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
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
$ npm install init-editorconfig
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
//
// [*]
// ...
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
- init-gitignore: Because making git ignore files should be easier.
- init-pkg-json: π¦ Complex generator of Package.json.
- init-pkg-json-cli: CLI for package.json generator π¦ .
- init-gitignore-cli: CLI for init-gitignore
- init-editorconfig-cli: CLI for this module π
Carlos Abraham |
MIT License Β© Carlos Abraham