alfonsox 0.1.1 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cee871a10b135714609282f329b904e12cccc9cc1b4d0d9291ea6cc77ee87ed
4
- data.tar.gz: 7aadff2c99d553a4fa964bf2bb519e190648a9471674a2464e3c669721f6af9c
3
+ metadata.gz: 8ca11c18b4eb8c01ef6470328f9f4707283501fff3f7c7ebeddc46cb3b8eba75
4
+ data.tar.gz: 1fce3b0a3819a688a467d70722186de55735acd3d427c3cba1dae1c1f6d798f6
5
5
  SHA512:
6
- metadata.gz: 8878a20418c1fc122944db6f5ece7f4a3221ec3e294f37e3e059316c5cf3149eb309037088ea39a860f791ff03c19d1e71380da89768b65d0a825810c8627a81
7
- data.tar.gz: 17ac27c4c7615f3b74549f2b7b3d2bda8ab86820b6acad7e69beaac6232d4dfb07d8037a7f6e115c61e61ec633ec474da64d7de9a0ea1565099574231333b2e6
6
+ metadata.gz: d4c63a337913d15722c4c3edadd94a970fe6c93dd919953b5fa5a5ded821f03cf2f4cd9995a76b1b85fdbd4bd207c95ca2f1467b72dd748d44efabd180dee05c
7
+ data.tar.gz: 753362cf0d9ffca8386b52c5928accaccf1302e93876e80a4c0b253d5e68990499724674e04c93634e05a88292e6a5cabef980ffdf60c6167b081630acdea80f
data/Gemfile CHANGED
@@ -1,8 +1,7 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in alfonsox.gemspec
6
5
  gemspec
7
6
 
8
7
  group :development, :test do
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- alfonsox (0.1.1)
5
- hunspell
6
- nokogiri (>= 1.8.5)
4
+ alfonsox (0.2.5)
5
+ hunspell (~> 1.1, >= 1.1.0)
6
+ nokogiri (~> 1.8, >= 1.8.5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -91,4 +91,4 @@ DEPENDENCIES
91
91
  simplecov-console
92
92
 
93
93
  BUNDLED WITH
94
- 1.16.2
94
+ 1.17.3
data/README.md CHANGED
@@ -21,7 +21,7 @@ gem 'alfonsox'
21
21
  And then execute:
22
22
 
23
23
  ```bash
24
- $ bundle
24
+ $ bundle install
25
25
  ```
26
26
 
27
27
  Or install it yourself as:
@@ -106,54 +106,9 @@ Dictionaries:
106
106
  type: 'rubymine'
107
107
  ```
108
108
 
109
- #### Rake task
109
+ #### Comnand line tool
110
110
 
111
- To use the rake task, you have to include the two following lines
112
- in your project's Rakefile:
113
-
114
- ```ruby
115
- alfonsox_gem = Gem::Specification.find_by_name('alfonsox')
116
- load("#{alfonsox_gem.gem_dir}/Rakefile")
117
- ```
118
-
119
- That two lines load all Alfonso X tasks' in your Rakefile.
120
-
121
- Our aim is to use **alfonsox:spellcheck** task.
122
-
123
- ##### Default configuration
124
-
125
- There is a [default configuration](/resources/configurations/default.yml)
126
- that will check US-English spelling and your RubyMine dictionary with your
127
- custom spellings.
128
-
129
- ```bash
130
- bundle exec rake alfonsox:spellcheck
131
- ```
132
-
133
- ##### Custom configuration
134
-
135
- Copy the [default configuration](/resources/configurations/default.yml)
136
- to your project root directory and modify it
137
-
138
- ```bash
139
- bundle exec rake alfonsox:spellcheck[<path/where/alfonsox.yml/file/is>]
140
- ```
141
-
142
- e.g.:
143
-
144
- ```bash
145
- bundle exec rake alfonsox:spellcheck[.alfonsox.yml]
146
- ```
147
-
148
- The rake task will output the spell checking errors, e.g.:
149
-
150
- ```bash
151
- $ bundle exec rake alfonsox:spellcheck[./test/resources/config.yml]
152
- Starting spellcheck using configuration ./test/resources/config.yml
153
- /Users/diegoj/proyectos/alfonsox/test/alfonsox_test.rb:8 jane
154
- /Users/diegoj/proyectos/alfonsox/test/alfonsox_test.rb:8 austen
155
- /Users/diegoj/proyectos/alfonsox/test/alfonsox_test.rb:70 neighbourhood
156
- ```
111
+ Just call **bundle exec alfonsox** and it should work fine, informing of any orthographic error in your code files.
157
112
 
158
113
  ### Overcommit integration
159
114
 
@@ -178,7 +133,7 @@ module Overcommit::Hook::PreCommit
178
133
 
179
134
  # Run rake spellcheck task
180
135
  args = flags + applicable_files
181
- result = execute('bundle exec rake alfonsox:spellcheck[.alfonsox.yml]', args: args)
136
+ result = execute('bundle exec alfonsox', args: args)
182
137
  spellchecking_errors = result.split('\n')
183
138
 
184
139
  # Check the if there are spelling errors
data/Rakefile CHANGED
@@ -24,20 +24,8 @@ namespace :alfonsox do
24
24
  end
25
25
 
26
26
  desc 'Spell checks a project'
27
- task :spellcheck, [:config_path] => [] do |_t, args|
28
- if args.config_path
29
- puts "Starting spellcheck using configuration #{args.config_path}"
30
- else
31
- puts 'No custom configuration, starting spellcheck using default configuration'
32
- end
33
- config_path = args.config_path || ALFONSOX_DEFAULT_CONFIGURATION_PATH
34
- spellchecker = AlfonsoX::SpellChecker::Main.from_config(config_path)
35
- spellchecker_errors_by_file = spellchecker.check
36
- spellchecker_errors_by_file.each do |file_path, spellchecker_errors|
37
- spellchecker_errors.each do |spellchecker_error_i|
38
- puts "#{file_path}:#{spellchecker_error_i.line} #{spellchecker_error_i.word}"
39
- end
40
- end
27
+ task :spellcheck do
28
+ AlfonsoX::CLI.new.run
41
29
  end
42
30
  end
43
31
 
data/alfonsox.gemspec CHANGED
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'alfonsox/version'
3
+ require_relative './lib/alfonsox/constants'
4
+ require_relative './lib/alfonsox/version'
6
5
 
7
6
  Gem::Specification.new do |spec|
8
7
  spec.name = 'alfonsox'
@@ -11,8 +10,8 @@ Gem::Specification.new do |spec|
11
10
  spec.email = ['diegojromerolopez@gmail.com']
12
11
 
13
12
  spec.summary = 'Spell checker for code'
14
- spec.description = 'Spell checker for code'
15
- spec.homepage = 'https://github.com/diegojromerolopez/alfonsox'
13
+ spec.description = 'Tool to detect orthography errors your code files'
14
+ spec.homepage = AlfonsoX::REPOSITORY_URL
16
15
  spec.license = 'MIT'
17
16
 
18
17
  # Specify which files should be added to the gem when it is released.
@@ -22,14 +21,15 @@ Gem::Specification.new do |spec|
22
21
  f.match(%r{^(test|spec|features)/})
23
22
  end
24
23
  end
25
- spec.bindir = 'exe'
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.executables = ['alfonsox']
27
25
  spec.require_paths = ['lib']
28
26
 
29
- spec.add_dependency 'hunspell'
30
- spec.add_dependency 'nokogiri', '>= 1.8.5'
27
+ spec.required_ruby_version = '>= 2.4'
28
+
29
+ spec.add_dependency 'hunspell', '~> 1.1', '>= 1.1.0'
30
+ spec.add_dependency 'nokogiri', '~> 1.8', '>= 1.8.5'
31
31
  spec.add_development_dependency 'bundler', '~> 1.16'
32
32
  spec.add_development_dependency 'minitest', '~> 5.0'
33
33
  spec.add_development_dependency 'rake', '~> 10.0'
34
- spec.add_development_dependency 'simplecov'
34
+ spec.add_development_dependency 'simplecov', '~> 0.16'
35
35
  end
data/bin/alfonsox ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'alfonsox/cli'
5
+
6
+ AlfonsoX::CLI.new.run
@@ -0,0 +1,10 @@
1
+ Paths:
2
+ - 'app/*/**.rb'
3
+ - 'lib/**.rb'
4
+ - 'test/**.rb'
5
+ Dictionaries:
6
+ EnglishDictionaryFromGem:
7
+ type: 'hunspell'
8
+ language: 'en_US'
9
+ RubymineDictionary:
10
+ type: 'rubymine'
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'alfonsox'
4
+
5
+ # Alfonso X module
6
+ module AlfonsoX
7
+ # Command Line Interpreter tool for Alfonso X
8
+ class CLI
9
+ # Success exit status code
10
+ SUCCESS_EXIT_STATUS = 0
11
+
12
+ # Error exit status code
13
+ ERROR_EXIT_STATUS = 1
14
+
15
+ # Take the config file path
16
+ def initialize
17
+ @config_file_path = config_file_path
18
+ end
19
+
20
+ # Run spell-check on files specified by config file
21
+ def run
22
+ spellchecker = AlfonsoX::SpellChecker::Main.from_config(@config_file_path)
23
+ spellchecker_errors_by_file = spellchecker.check
24
+ exit_status = SUCCESS_EXIT_STATUS
25
+ spellchecker_errors_by_file.each do |file_path, spellchecker_errors|
26
+ spellchecker_errors.each do |spellchecker_error_i|
27
+ print_spellcheck_error(file_path, spellchecker_error_i)
28
+ exit_status = ERROR_EXIT_STATUS
29
+ end
30
+ end
31
+
32
+ print_status(exit_status)
33
+ exit(exit_status)
34
+ end
35
+
36
+ private
37
+
38
+ # Return the config file path
39
+ # @return [String] config file path that will be used when running Alfonso X tool.
40
+ def config_file_path
41
+ repo_config_file_path_yml = File.join(AlfonsoX::Utils.repo_root, AlfonsoX::CONFIG_FILE_NAME)
42
+ return repo_config_file_path_yml if File.exist?(repo_config_file_path_yml)
43
+ File.join(AlfonsoX::CONFIG_PATH, 'default.yml')
44
+ end
45
+
46
+ # Shows a lone spellcheck error in the standard error output
47
+ def print_spellcheck_error(file_path, spellchecker_error)
48
+ STDERR.puts "#{file_path}:#{spellchecker_error.line} #{spellchecker_error.word}"
49
+ end
50
+
51
+ # Print status of the spellcheck
52
+ def print_status(exit_status)
53
+ if exit_status == SUCCESS_EXIT_STATUS
54
+ print_success_status
55
+ elsif exit_status == ERROR_EXIT_STATUS
56
+ print_error_status
57
+ end
58
+ end
59
+
60
+ # Informs that everything went well
61
+ def print_success_status
62
+ STDOUT.puts '✔ Code is spell-checked correctly'
63
+ end
64
+
65
+ # Informs that something went wrong
66
+ def print_error_status
67
+ STDERR.puts '✗ Errors in in code spellchecking'
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Alfonso X module
4
+ module AlfonsoX
5
+ ROOT_PATH = "#{__dir__}/../.."
6
+ CONFIG_PATH = "#{AlfonsoX::ROOT_PATH}/config"
7
+ LIB_PATH = "#{AlfonsoX::ROOT_PATH}/lib"
8
+ RESOURCES_PATH = "#{AlfonsoX::ROOT_PATH}/resources"
9
+ DICTIONARIES_PATH = "#{AlfonsoX::RESOURCES_PATH}/dictionaries"
10
+ DEFAULT_CONFIGURATION_PATH = "#{AlfonsoX::CONFIG_PATH}/config/default.yml"
11
+
12
+ # Configuration file name in repositories that use this tool
13
+ CONFIG_FILE_NAME = '.alfonsox.yml'
14
+
15
+ # Alfonso X repository URL
16
+ REPOSITORY_URL = 'https://github.com/diegojromerolopez/alfonsox'
17
+ end
@@ -57,12 +57,17 @@ module AlfonsoX
57
57
 
58
58
  # Other common but erroneous words in the Ruby-development world
59
59
  OTHERS = %w[
60
+ asc
60
61
  autorun
61
62
  autotest
63
+ bigint
62
64
  config
63
65
  const
64
66
  cov
67
+ datetime
68
+ desc
65
69
  dir
70
+ env
66
71
  formatter
67
72
  klass
68
73
  rb
@@ -9,7 +9,7 @@ module AlfonsoX
9
9
  # Hunspell dictionary loader
10
10
  class Hunspell
11
11
  # Default hunspell dictionary path
12
- DEFAULT_PATH = "#{ALFONSOX_DICTIONARIES_PATH}/hunspell"
12
+ DEFAULT_PATH = "#{AlfonsoX::DICTIONARIES_PATH}/hunspell"
13
13
  # All atributtes are readable
14
14
  attr_reader :language, :path
15
15
 
@@ -43,7 +43,7 @@ module AlfonsoX
43
43
  # Finds the dictionary in this Gem
44
44
  class DictionaryFinder
45
45
  attr_reader :aff_file_path, :dic_file_path
46
- PATH = "#{ALFONSOX_DICTIONARIES_PATH}/hunspell"
46
+ PATH = "#{AlfonsoX::DICTIONARIES_PATH}/hunspell"
47
47
 
48
48
  def initialize(language, path = nil)
49
49
  @language = language
@@ -53,7 +53,7 @@ module AlfonsoX
53
53
  end
54
54
 
55
55
  def find
56
- paths = [@path, "#{ALFONSOX_DICTIONARIES_PATH}/hunspell"].compact
56
+ paths = [@path, "#{AlfonsoX::DICTIONARIES_PATH}/hunspell"].compact
57
57
  paths.each do |path|
58
58
  @aff_file_path, @dic_file_path = DictionaryFinder.find_from_language(@language, path)
59
59
  return true if @aff_file_path && @dic_file_path
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+
5
+ # A Alfonso X module
6
+ module AlfonsoX
7
+ # Utils for Alfonso X
8
+ module Utils
9
+ # Module static methods
10
+ class << self
11
+ # Returns an absolute path to the root of the repository.
12
+ #
13
+ # Stolen from Overcommit::Utils#repo_root
14
+ #
15
+ # We do this ourselves rather than call `git rev-parse --show-toplevel` to
16
+ # solve an issue where the .git directory might not actually be valid in
17
+ # tests.
18
+ #
19
+ # @return [String] GIT root file path
20
+ def repo_root
21
+ result = `git rev-parse --show-toplevel`
22
+ raise 'Not in git repository' unless $CHILD_STATUS.success?
23
+ result.chomp("\n")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AlfonsoX
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.5'
5
5
  end
data/lib/alfonsox.rb CHANGED
@@ -1,12 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Some useful path constants
4
- ALFONSOX_LIB_PATH = __dir__
5
- ALFONSOX_RESOURCES_PATH = "#{__dir__}/../resources"
6
- ALFONSOX_DICTIONARIES_PATH = "#{ALFONSOX_RESOURCES_PATH}/dictionaries"
7
- ALFONSOX_DEFAULT_CONFIGURATION_PATH = "#{ALFONSOX_RESOURCES_PATH}/configurations/default.yml"
8
-
9
3
  require 'alfonsox/version'
4
+ require 'alfonsox/constants'
5
+ require 'alfonsox/utils'
10
6
  require 'alfonsox/spellchecker/dictionaries'
11
7
  require 'alfonsox/spellchecker/main'
12
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alfonsox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego J. Romero López
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-11 00:00:00.000000000 Z
11
+ date: 2019-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hunspell
@@ -16,18 +16,27 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.1.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: 1.1.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.1'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: nokogiri
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.8'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
42
  version: 1.8.5
@@ -35,6 +44,9 @@ dependencies:
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.8'
38
50
  - - ">="
39
51
  - !ruby/object:Gem::Version
40
52
  version: 1.8.5
@@ -84,20 +96,21 @@ dependencies:
84
96
  name: simplecov
85
97
  requirement: !ruby/object:Gem::Requirement
86
98
  requirements:
87
- - - ">="
99
+ - - "~>"
88
100
  - !ruby/object:Gem::Version
89
- version: '0'
101
+ version: '0.16'
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
93
105
  requirements:
94
- - - ">="
106
+ - - "~>"
95
107
  - !ruby/object:Gem::Version
96
- version: '0'
97
- description: Spell checker for code
108
+ version: '0.16'
109
+ description: Tool to detect orthography errors your code files
98
110
  email:
99
111
  - diegojromerolopez@gmail.com
100
- executables: []
112
+ executables:
113
+ - alfonsox
101
114
  extensions: []
102
115
  extra_rdoc_files: []
103
116
  files:
@@ -112,9 +125,11 @@ files:
112
125
  - README.md
113
126
  - Rakefile
114
127
  - alfonsox.gemspec
115
- - bin/console
116
- - bin/setup
128
+ - bin/alfonsox
129
+ - config/default.yml
117
130
  - lib/alfonsox.rb
131
+ - lib/alfonsox/cli.rb
132
+ - lib/alfonsox/constants.rb
118
133
  - lib/alfonsox/spellchecker/dictionaries.rb
119
134
  - lib/alfonsox/spellchecker/dictionary/default.rb
120
135
  - lib/alfonsox/spellchecker/dictionary/hunspell.rb
@@ -123,6 +138,7 @@ files:
123
138
  - lib/alfonsox/spellchecker/file.rb
124
139
  - lib/alfonsox/spellchecker/main.rb
125
140
  - lib/alfonsox/spellchecker/word.rb
141
+ - lib/alfonsox/utils.rb
126
142
  - lib/alfonsox/version.rb
127
143
  - resources/configurations/default.yml
128
144
  - resources/dictionaries/hunspell/README.md
@@ -306,15 +322,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
306
322
  requirements:
307
323
  - - ">="
308
324
  - !ruby/object:Gem::Version
309
- version: '0'
325
+ version: '2.4'
310
326
  required_rubygems_version: !ruby/object:Gem::Requirement
311
327
  requirements:
312
328
  - - ">="
313
329
  - !ruby/object:Gem::Version
314
330
  version: '0'
315
331
  requirements: []
316
- rubyforge_project:
317
- rubygems_version: 2.7.3
332
+ rubygems_version: 3.0.4
318
333
  signing_key:
319
334
  specification_version: 4
320
335
  summary: Spell checker for code
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'alfonsox'
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(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here