editorconfig_generator 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.editorconfig +8 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +34 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/Makefile +2 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/changelog.md +34 -0
- data/circle.yml +3 -0
- data/editorconfig-generator.gemspec +29 -0
- data/install.sh +74 -0
- data/lib/editorconfig/argument_parser.rb +112 -0
- data/lib/editorconfig/editor_config.rb +155 -0
- data/lib/editorconfig/file_generator.rb +29 -0
- data/lib/editorconfig/option_transformer.rb +34 -0
- data/lib/editorconfig/version.rb +3 -0
- data/lib/generator.rb +10 -0
- data/readme.md +45 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f17ee5e6d3ac647945821d2b8d807040cdd443b8
|
4
|
+
data.tar.gz: 9a37262dfc1ca05a74cf7216b70dafe8a45b4eb8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48c3080114efb8a4cda1c96bd29180e64032001c309ad72023dda2472f7275cdb325e965e2c21712c5218c25c31ef8cc4daee3ae0c214b5c318341605f45f9d0
|
7
|
+
data.tar.gz: 9881bf4acf35932afbaa99b2f9b4c17ae52022c235bb8c913f82152e1b47b0eb927d02c2fd02d060466632204fb9a4b046e2a7b6caecefb93466be23e9cc9719
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
# The EditorConfig class represents the .editorconfig file.
|
4
|
+
#
|
5
|
+
# This class has a fair amount of content and logic associated
|
6
|
+
# with it that doesn't make sense elsewhere, therefore I've
|
7
|
+
# decided to double the ClassLength requirements.
|
8
|
+
#
|
9
|
+
# Hopefully, this doesn't promote objects or classes that are
|
10
|
+
# too complex.
|
11
|
+
Metrics/ClassLength:
|
12
|
+
Exclude:
|
13
|
+
- 'lib/editorconfig/editor_config.rb'
|
14
|
+
|
15
|
+
# Specs shouldn't have a length cap as they should be verbose by
|
16
|
+
# design.
|
17
|
+
Metrics/ModuleLength:
|
18
|
+
Exclude:
|
19
|
+
- "**/*_spec.rb"
|
20
|
+
|
21
|
+
Metrics/BlockLength:
|
22
|
+
Exclude:
|
23
|
+
- "**/*_spec.rb"
|
24
|
+
|
25
|
+
Metrics/LineLength:
|
26
|
+
Exclude:
|
27
|
+
- "**/*_spec.rb"
|
28
|
+
|
29
|
+
# The File Generator specs usually have longer example length
|
30
|
+
# due to string matching setup representing file content
|
31
|
+
RSpec/ExampleLength:
|
32
|
+
Exclude:
|
33
|
+
- 'spec/editor_config_generator/file_generator_spec.rb'
|
34
|
+
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at m.oluogunleye94@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Muyiwa Olu-Ogunleye
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Makefile
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'editorconfig/generator'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/changelog.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
### Added
|
9
|
+
|
10
|
+
## [0.2.3] - 18/03/2017
|
11
|
+
### Added
|
12
|
+
- Fix issue with the parser not running due to missing parameter
|
13
|
+
- Improve `install.sh`, do a few defensive checks
|
14
|
+
- Add support for `make`
|
15
|
+
|
16
|
+
## [0.2.2] - 13/03/2017
|
17
|
+
### Added
|
18
|
+
- Add rubocop support for the project
|
19
|
+
- Refactor each file that reports a rubocop violation
|
20
|
+
- Add support for continuous integration with rubocop
|
21
|
+
- Removed Travis CI and use Circle CI instead
|
22
|
+
|
23
|
+
## [0.2.1] - 02/12/2016
|
24
|
+
### Added
|
25
|
+
- Updated readme to add FAQ section
|
26
|
+
- Added FAQ question about file types
|
27
|
+
- Added ability for EditorConfig object to know if it is a 'minimum' object (where minimum is if only the `root` and `file_type` are not nil
|
28
|
+
- Added a changelog
|
29
|
+
- Improved the EditorConfig object to initialise all instance variables
|
30
|
+
|
31
|
+
[Unreleased]: https://github.com/muyiwaolu/editorconfig-generator/compare/v0.2.2...HEAD
|
32
|
+
[0.2.1]: https://github.com/muyiwaolu/editorconfig-generator/compare/v0.2.0...v0.2.1
|
33
|
+
[0.2.2]: https://github.com/muyiwaolu/editorconfig-generator/compare/v0.2.1...v0.2.2
|
34
|
+
[0.2.3]: https://github.com/muyiwaolu/editorconfig-generator/compare/v0.2.2...v0.2.3
|
data/circle.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'editorconfig/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'editorconfig_generator'
|
8
|
+
spec.version = EditorConfigGenerator::VERSION
|
9
|
+
spec.authors = ['Muyiwa Olu-Ogunleye']
|
10
|
+
spec.email = ['hello@muyiwa.me']
|
11
|
+
|
12
|
+
spec.summary = 'Allow users to generate .editorconfig files.'
|
13
|
+
spec.description = 'Allow users to generate .editorconfig files quickly and
|
14
|
+
easily using presets or custom options.'
|
15
|
+
spec.homepage = 'https://github.com/muyiwaolu/editorconfig_generator'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
28
|
+
spec.required_ruby_version = '~> 2.0'
|
29
|
+
end
|
data/install.sh
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
EDITORCONFIG_PATH="$HOME/.editorconfig-generator"
|
3
|
+
EDITORCONFIG_LIBRARY_DIR="$EDITORCONFIG_PATH/lib/editorconfig"
|
4
|
+
EDITORCONFIG_SCRIPT_FILE="$EDITORCONFIG_PATH/lib/generator.rb"
|
5
|
+
BIN_DIRECTORY="/usr/local/bin"
|
6
|
+
GENERATOR_LOCATION="$BIN_DIRECTORY/generator"
|
7
|
+
|
8
|
+
function echo_message() {
|
9
|
+
echo "$1"
|
10
|
+
}
|
11
|
+
|
12
|
+
function remove_existing_generator() {
|
13
|
+
if [ -f "$GENERATOR_LOCATION" ] ; then
|
14
|
+
echo_message "Removing existing generator binary located at: [$GENERATOR_LOCATION]"
|
15
|
+
if rm "$GENERATOR_LOCATION" ; then
|
16
|
+
echo_message "Removed existing generator binary successfully."
|
17
|
+
else
|
18
|
+
echo_message "Unable to remove existing generator binary."
|
19
|
+
fi
|
20
|
+
else
|
21
|
+
echo_message "[$GENERATOR_LOCATION] does not exist. Skipping removing binary..."
|
22
|
+
fi
|
23
|
+
}
|
24
|
+
|
25
|
+
function link_generator() {
|
26
|
+
if [ -f "$EDITORCONFIG_SCRIPT_FILE" ] && [ -d "$BIN_DIRECTORY" ] ; then
|
27
|
+
echo_message "Symbolically linking [$EDITORCONFIG_SCRIPT_FILE] to [$GENERATOR_LOCATION]"
|
28
|
+
if ln -sf "$EDITORCONFIG_SCRIPT_FILE" "$GENERATOR_LOCATION" ; then
|
29
|
+
echo_message "Successfully linked the files"
|
30
|
+
else
|
31
|
+
echo_message "Unable to link the files"
|
32
|
+
fi
|
33
|
+
else
|
34
|
+
echo_message "[$EDITORCONFIG_SCRIPT_FILE] or [$BIN_DIRECTORY] does not exist..."
|
35
|
+
fi
|
36
|
+
}
|
37
|
+
|
38
|
+
function link_generator_directory() {
|
39
|
+
if [ -d "$EDITORCONFIG_LIBRARY_DIR" ] && [ -d "$BIN_DIRECTORY" ] ; then
|
40
|
+
echo_message "Symbolically linking [$EDITORCONFIG_LIBRARY_DIR] to [$BIN_DIRECTORY]"
|
41
|
+
if ln -sf "$EDITORCONFIG_LIBRARY_DIR" "$BIN_DIRECTORY" ; then
|
42
|
+
echo_message "Successfully linked the directories"
|
43
|
+
else
|
44
|
+
echo_message "Unable to link the directories"
|
45
|
+
fi
|
46
|
+
else
|
47
|
+
echo_message "[$EDITORCONFIG_LIBRARY_DIR] or [$BIN_DIRECTORY] does not exist..."
|
48
|
+
fi
|
49
|
+
}
|
50
|
+
|
51
|
+
function write_permissions_to_generator() {
|
52
|
+
|
53
|
+
if [ -f "$GENERATOR_LOCATION" ] ; then
|
54
|
+
if chmod +x "$GENERATOR_LOCATION" ; then
|
55
|
+
echo_message "Sucessfully given write permissions to [$GENERATOR_LOCATION]"
|
56
|
+
else
|
57
|
+
echo_message "Unable to give write permissions to [$GENERATOR_LOCATION]"
|
58
|
+
fi
|
59
|
+
else
|
60
|
+
echo_message "[$GENERATOR_LOCATION] doesn't exist"
|
61
|
+
fi
|
62
|
+
|
63
|
+
|
64
|
+
}
|
65
|
+
|
66
|
+
remove_existing_generator
|
67
|
+
link_generator
|
68
|
+
link_generator_directory
|
69
|
+
write_permissions_to_generator
|
70
|
+
|
71
|
+
#ln -sf ~/.editorconfig-generator/lib/generator.rb /usr/local/bin/generator # Link the generator script to the bin path
|
72
|
+
#chmod +x /usr/local/bin/generator # Give the script appropriate permissions
|
73
|
+
#
|
74
|
+
#ln -sf ~/.editorconfig-generator/lib/editorconfig /usr/local/bin # Link the supporting files to the binary location
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require_relative './option_transformer'
|
3
|
+
require_relative './editor_config'
|
4
|
+
require_relative './file_generator'
|
5
|
+
|
6
|
+
module EditorConfigGenerator
|
7
|
+
# Parses the arguments passed to the Editor Configurator
|
8
|
+
class ArgumentParser
|
9
|
+
def self.ask_user(options)
|
10
|
+
ask_file_type(options)
|
11
|
+
ask_indent_style(options)
|
12
|
+
ask_indent_size(options)
|
13
|
+
ask_end_of_line(options)
|
14
|
+
ask_charset(options)
|
15
|
+
ask_trailing_whitespace(options)
|
16
|
+
ask_insert_newline(options)
|
17
|
+
ask_question('Would you like to add another (file specific) section
|
18
|
+
(y/n) [n]', %w(y n), 'n')
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.ask_insert_newline(options)
|
22
|
+
options[:insert_final_newline] = ask_question('Would you like to insert
|
23
|
+
a final newline? (y/n)',
|
24
|
+
%w(y n))
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.ask_trailing_whitespace(options)
|
28
|
+
options[:trim_trailing_whitespace] = ask_question('Would you like to trim
|
29
|
+
trailing whitespace?
|
30
|
+
(y/n)', %w(y n))
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.ask_charset(options)
|
34
|
+
options[:charset] = ask_question('What is the character set of the
|
35
|
+
project? (latin1/utf-8/utf-8-bom
|
36
|
+
/utf-16be/utf-16le)',
|
37
|
+
%w(latin utf-8 utf-8-bom
|
38
|
+
utf-16be utf-16le))
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.ask_end_of_line(options)
|
42
|
+
options[:end_of_line] = ask_question('What character would you like to
|
43
|
+
use to represent the end of line?
|
44
|
+
(lf/cr/ctrlf)', %w(cr lf ctrlf))
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.ask_indent_size(options)
|
48
|
+
options[:indent_size] = ask_question('What size would you like
|
49
|
+
indentations to be? ', %w(2 4))
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.ask_indent_style(options)
|
53
|
+
options[:indent_style] = ask_question('What indent style do you use
|
54
|
+
(space/tabs)', %w(space tabs))
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.ask_file_type(options)
|
58
|
+
options[:file_type] = ask_question('What is the filetype for these rules?
|
59
|
+
[*]', nil, '*')
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.ask_question(question, valid_answers, default_value = nil)
|
63
|
+
loop do
|
64
|
+
print "#{question}: "
|
65
|
+
answer = STDIN.gets.chomp
|
66
|
+
return default_value if answer.chomp == ''
|
67
|
+
return answer if !valid_answers.nil? && valid_answers.include?(answer)
|
68
|
+
return answer if valid_answers.nil?
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.parse(args)
|
73
|
+
option_parser = OptionParser.new do |options|
|
74
|
+
options.banner = "Generates a .editorconfig file with settings of your
|
75
|
+
choosing.
|
76
|
+
\nUsage: editorconfig generate "
|
77
|
+
parse_options(options)
|
78
|
+
end
|
79
|
+
option_parser.parse!(args)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.parse_options(options)
|
83
|
+
option_prompt = 'Generate an editorconfig file.'
|
84
|
+
options.on('-g', '--generate', option_prompt) do |_answer|
|
85
|
+
configs = []
|
86
|
+
options = {}
|
87
|
+
options[:root] = ask_question('Is this for the topmost .editorconfig
|
88
|
+
file? (y/n) [y]', %w(y n), 'y')
|
89
|
+
ask_questions(options)
|
90
|
+
file_generator = FileGenerator.new(configs)
|
91
|
+
file_generator.generate_config_file
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def ask_questions(options, configs)
|
96
|
+
loop do
|
97
|
+
add_another_config = ask_user(options)
|
98
|
+
e = EditorConfig.new(options)
|
99
|
+
configs.push(e)
|
100
|
+
options = {}
|
101
|
+
warn_user_bare_minimum(add_another_config, e)
|
102
|
+
break if add_another_config == 'n'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def warn_user_bare_minimum(add_another_config, e)
|
107
|
+
return unless add_another_config == 'n' && e.minimum?
|
108
|
+
puts 'Warning: you have selected the bare minimum options for the
|
109
|
+
file'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
module EditorConfigGenerator
|
2
|
+
# Object representation of an EditorConfig file
|
3
|
+
# rubocop:disable Style/AccessorMethodName
|
4
|
+
class EditorConfig
|
5
|
+
attr_reader :root, :indent_style, :indent_size,
|
6
|
+
:end_of_line, :charset, :trim_trailing_whitespace,
|
7
|
+
:insert_final_newline, :file_type
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
@root = nil
|
11
|
+
@file_type = :*
|
12
|
+
@indent_style = nil
|
13
|
+
@end_of_line = nil
|
14
|
+
@charset = nil
|
15
|
+
@trim_trailing_whitespace = nil
|
16
|
+
@insert_final_newline = nil
|
17
|
+
|
18
|
+
OptionTransformer.transform_options(options)
|
19
|
+
set_options(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_options(options)
|
23
|
+
set_root_option(options)
|
24
|
+
set_indent_style_option(options)
|
25
|
+
set_indent_size_option(options)
|
26
|
+
set_end_of_line_option(options)
|
27
|
+
set_charset_option(options)
|
28
|
+
set_trailing_space_option(options)
|
29
|
+
set_final_newline_option(options)
|
30
|
+
set_file_type_option(options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_file_type_option(options)
|
34
|
+
return if options[:file_type].nil?
|
35
|
+
@file_type = options[:file_type]
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_final_newline_option(options)
|
39
|
+
return if options[:insert_final_newline].nil?
|
40
|
+
@insert_final_newline = options[:insert_final_newline]
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_trailing_space_option(options)
|
44
|
+
return if options[:trim_trailing_whitespace].nil?
|
45
|
+
@trim_trailing_whitespace = options[:trim_trailing_whitespace]
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_charset_option(options)
|
49
|
+
return if options[:charset].nil?
|
50
|
+
@charset = options[:charset]
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_end_of_line_option(options)
|
54
|
+
return if options[:end_of_line].nil?
|
55
|
+
@end_of_line = options[:end_of_line]
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_indent_size_option(options)
|
59
|
+
return if options[:indent_size].nil?
|
60
|
+
@indent_size = options[:indent_size]
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_indent_style_option(options)
|
64
|
+
return if options[:indent_style].nil?
|
65
|
+
@indent_style = options[:indent_style]
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_root_option(options)
|
69
|
+
return if options[:root].nil?
|
70
|
+
@root = options[:root]
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_s
|
74
|
+
config_string = ''
|
75
|
+
append_root_to_s(config_string)
|
76
|
+
append_file_type_to_s(config_string)
|
77
|
+
append_indent_style_to_s(config_string)
|
78
|
+
append_indent_size_to_s(config_string)
|
79
|
+
append_end_of_line_to_s(config_string)
|
80
|
+
append_charset_to_s(config_string)
|
81
|
+
append_whitespace_to_s(config_string)
|
82
|
+
append_final_newline_to_s(config_string)
|
83
|
+
config_string
|
84
|
+
end
|
85
|
+
|
86
|
+
def append_final_newline_to_s(config_string)
|
87
|
+
return if @insert_final_newline.nil?
|
88
|
+
config_string << "insert_final_newline = #{@insert_final_newline}\n"
|
89
|
+
end
|
90
|
+
|
91
|
+
def append_whitespace_to_s(config_string)
|
92
|
+
return if @trim_trailing_whitespace.nil?
|
93
|
+
config_string << 'trim_trailing_whitespace ' \
|
94
|
+
"= #{@trim_trailing_whitespace}\n"
|
95
|
+
end
|
96
|
+
|
97
|
+
def append_charset_to_s(config_string)
|
98
|
+
return if @charset.nil?
|
99
|
+
config_string << "charset = #{@charset}\n"
|
100
|
+
end
|
101
|
+
|
102
|
+
def append_end_of_line_to_s(config_string)
|
103
|
+
return if @end_of_line.nil?
|
104
|
+
config_string << "end_of_line = #{@end_of_line}\n"
|
105
|
+
end
|
106
|
+
|
107
|
+
def append_indent_size_to_s(config_string)
|
108
|
+
return if @indent_size.nil?
|
109
|
+
config_string << "indent_size = #{@indent_size}\n"
|
110
|
+
end
|
111
|
+
|
112
|
+
def append_indent_style_to_s(config_string)
|
113
|
+
return if @indent_style.nil?
|
114
|
+
config_string << "indent_style = #{@indent_style}\n"
|
115
|
+
end
|
116
|
+
|
117
|
+
def append_file_type_to_s(config_string)
|
118
|
+
config_string << "[#{@file_type}]\n"
|
119
|
+
end
|
120
|
+
|
121
|
+
def append_root_to_s(config_string)
|
122
|
+
return if @root.nil?
|
123
|
+
config_string << "root = #{@root}\n"
|
124
|
+
end
|
125
|
+
|
126
|
+
def to_s_without_root
|
127
|
+
lines = to_s.lines
|
128
|
+
lines.delete_at 0
|
129
|
+
lines.join
|
130
|
+
end
|
131
|
+
|
132
|
+
def to_s_without_line(line_identifier)
|
133
|
+
lines = to_s.lines
|
134
|
+
index = lines.index(line_identifier)
|
135
|
+
lines.delete_at index
|
136
|
+
lines.join
|
137
|
+
end
|
138
|
+
|
139
|
+
def minimum?
|
140
|
+
# The minimum editor config file is one with only root and file_type set
|
141
|
+
@indent_style.nil? &&
|
142
|
+
@indent_size.nil? &&
|
143
|
+
@end_of_line.nil? &&
|
144
|
+
@charset.nil? &&
|
145
|
+
@trim_trailing_whitespace.nil? &&
|
146
|
+
@insert_final_newline.nil?
|
147
|
+
end
|
148
|
+
|
149
|
+
def defaults?
|
150
|
+
minimum? &&
|
151
|
+
@file_type == :* &&
|
152
|
+
@root.nil?
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module EditorConfigGenerator
|
2
|
+
# Generates a .editorconfig file when given a valid configuration object
|
3
|
+
class FileGenerator
|
4
|
+
def initialize(configs)
|
5
|
+
@configs = configs
|
6
|
+
end
|
7
|
+
|
8
|
+
def preview_output
|
9
|
+
output = ''
|
10
|
+
@configs.each do |config|
|
11
|
+
if output.include? 'root='
|
12
|
+
output << config.to_s_without_root
|
13
|
+
next
|
14
|
+
end
|
15
|
+
output << config.to_s
|
16
|
+
end
|
17
|
+
return output.rstrip if @configs.size > 1
|
18
|
+
output
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_config_file(location = '.editorconfig')
|
22
|
+
File.delete(location) if File.exist? location
|
23
|
+
file = File.new(location, 'w')
|
24
|
+
file.print(preview_output)
|
25
|
+
file.close
|
26
|
+
file
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module EditorConfigGenerator
|
2
|
+
# Transforms options given to an EditorConfig object
|
3
|
+
class OptionTransformer
|
4
|
+
def self.transform_options(options)
|
5
|
+
transform_root_option(options)
|
6
|
+
transform_whitespace_option(options)
|
7
|
+
transform_final_newline_option(options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.transform_final_newline_option(options)
|
11
|
+
if options[:insert_final_newline] == 'y'
|
12
|
+
options[:insert_final_newline] = true
|
13
|
+
elsif options[:insert_final_newline] == 'n'
|
14
|
+
options[:insert_final_newline] = false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.transform_whitespace_option(options)
|
19
|
+
if options[:trim_trailing_whitespace] == 'y'
|
20
|
+
options[:trim_trailing_whitespace] = true
|
21
|
+
elsif options[:trim_trailing_whitespace] == 'n'
|
22
|
+
options[:trim_trailing_whitespace] = false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.transform_root_option(options)
|
27
|
+
if options[:root] == 'y'
|
28
|
+
options[:root] = true
|
29
|
+
elsif options[:root] == 'n'
|
30
|
+
options[:root] = false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/generator.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative './editorconfig/argument_parser'
|
4
|
+
|
5
|
+
# The module that encapsulates all of the EditorConfig logic
|
6
|
+
module EditorConfigGenerator
|
7
|
+
# Automatically load the help if invalid arguments are given.
|
8
|
+
ARGV.push('-h') if ARGV.empty? || ARGV != '-g' || ARGV != '--generate'
|
9
|
+
ArgumentParser.parse(ARGV)
|
10
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
[](https://circleci.com/gh/muyiwaolu/editorconfig-generator)
|
2
|
+
# EditorConfig Generator
|
3
|
+
A command line ruby script that allows you to generate .editorconfig files quickly and easily using presets or custom options.
|
4
|
+
|
5
|
+
The source code for the script is located in the [lib](https://github.com/muyiwaolu/editorconfig-generator/tree/master/lib) directory.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Clone the repository into `~/.editor-config`, e.g. `git clone https://github.com/muyiwaolu/editorconfig-generator ~/.editorconfig-generator`
|
10
|
+
|
11
|
+
__Note:__ Before the next steps, please make sure you read and understand what `install.sh` is doing. I've written this script, and will be the first to admit I am _not_ a shell script expert.
|
12
|
+
|
13
|
+
On that note, I will happily accept pull requests to improve it.
|
14
|
+
|
15
|
+
2. `cd` into the `~/.editor-config` directory and run `install.sh`. You may want to run `chmod +x install.sh` first if the command line complains about incorrect permissions.
|
16
|
+
|
17
|
+
3. Link the appropriate files by running `./install.sh`
|
18
|
+
|
19
|
+
4. If you run `generator`, you should see the following prompt:
|
20
|
+
|
21
|
+
```
|
22
|
+
Generates a .editorconfig file with settings of your choosing.
|
23
|
+
|
24
|
+
Usage: editorconfig generate
|
25
|
+
-g, --generate Generate an editorconfig file.
|
26
|
+
```
|
27
|
+
|
28
|
+
## FAQ
|
29
|
+
|
30
|
+
1. Why aren't my specific file rules being recognised?
|
31
|
+
|
32
|
+
Make sure to put in the correct file matching pattern. For example, to match all files with the `.js` extension, enter `*.js`. [More information here](http://editorconfig.org/#file-format-details).
|
33
|
+
|
34
|
+
## Upgrading
|
35
|
+
|
36
|
+
Since the files are symbolically linked to your `/usr/local/bin` folder, to upgrade to the latest version, simply `cd` into `~/.editor-config` and `git pull`.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome here on [GitHub](https://github.com/muyiwaolu/editorconfig-generator). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org/) code of conduct.
|
41
|
+
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: editorconfig_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Muyiwa Olu-Ogunleye
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
description: |-
|
56
|
+
Allow users to generate .editorconfig files quickly and
|
57
|
+
easily using presets or custom options.
|
58
|
+
email:
|
59
|
+
- hello@muyiwa.me
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".editorconfig"
|
65
|
+
- ".gitignore"
|
66
|
+
- ".rspec"
|
67
|
+
- ".rubocop.yml"
|
68
|
+
- CODE_OF_CONDUCT.md
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- Makefile
|
72
|
+
- Rakefile
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- changelog.md
|
76
|
+
- circle.yml
|
77
|
+
- editorconfig-generator.gemspec
|
78
|
+
- install.sh
|
79
|
+
- lib/editorconfig/argument_parser.rb
|
80
|
+
- lib/editorconfig/editor_config.rb
|
81
|
+
- lib/editorconfig/file_generator.rb
|
82
|
+
- lib/editorconfig/option_transformer.rb
|
83
|
+
- lib/editorconfig/version.rb
|
84
|
+
- lib/generator.rb
|
85
|
+
- readme.md
|
86
|
+
homepage: https://github.com/muyiwaolu/editorconfig_generator
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '2.0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.6.8
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Allow users to generate .editorconfig files.
|
110
|
+
test_files: []
|