danger-ormolu 0.0.1

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.
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.0
8
+ - 2.1.3
9
+ - 2.3.1
10
+
11
+ script:
12
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-ormolu.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,149 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-ormolu (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.2)
13
+ claide (1.0.3)
14
+ claide-plugins (0.9.2)
15
+ cork
16
+ nap
17
+ open4 (~> 1.3)
18
+ coderay (1.1.3)
19
+ colored2 (3.1.2)
20
+ cork (0.3.0)
21
+ colored2 (~> 3.1)
22
+ danger (8.2.2)
23
+ claide (~> 1.0)
24
+ claide-plugins (>= 0.9.2)
25
+ colored2 (~> 3.1)
26
+ cork (~> 0.1)
27
+ faraday (>= 0.9.0, < 2.0)
28
+ faraday-http-cache (~> 2.0)
29
+ git (~> 1.7)
30
+ kramdown (~> 2.3)
31
+ kramdown-parser-gfm (~> 1.0)
32
+ no_proxy_fix
33
+ octokit (~> 4.7)
34
+ terminal-table (~> 1)
35
+ danger-plugin-api (1.0.0)
36
+ danger (> 2.0)
37
+ diff-lcs (1.4.4)
38
+ faraday (1.3.0)
39
+ faraday-net_http (~> 1.0)
40
+ multipart-post (>= 1.2, < 3)
41
+ ruby2_keywords
42
+ faraday-http-cache (2.2.0)
43
+ faraday (>= 0.8)
44
+ faraday-net_http (1.0.1)
45
+ ffi (1.14.2)
46
+ formatador (0.2.5)
47
+ git (1.8.1)
48
+ rchardet (~> 1.8)
49
+ guard (2.16.2)
50
+ formatador (>= 0.2.4)
51
+ listen (>= 2.7, < 4.0)
52
+ lumberjack (>= 1.0.12, < 2.0)
53
+ nenv (~> 0.1)
54
+ notiffany (~> 0.0)
55
+ pry (>= 0.9.12)
56
+ shellany (~> 0.0)
57
+ thor (>= 0.18.1)
58
+ guard-compat (1.2.1)
59
+ guard-rspec (4.7.3)
60
+ guard (~> 2.1)
61
+ guard-compat (~> 1.1)
62
+ rspec (>= 2.99.0, < 4.0)
63
+ kramdown (2.3.0)
64
+ rexml
65
+ kramdown-parser-gfm (1.1.0)
66
+ kramdown (~> 2.0)
67
+ listen (3.0.7)
68
+ rb-fsevent (>= 0.9.3)
69
+ rb-inotify (>= 0.9.7)
70
+ lumberjack (1.2.8)
71
+ method_source (1.0.0)
72
+ multipart-post (2.1.1)
73
+ nap (1.1.0)
74
+ nenv (0.3.0)
75
+ no_proxy_fix (0.1.2)
76
+ notiffany (0.1.3)
77
+ nenv (~> 0.1)
78
+ shellany (~> 0.0)
79
+ octokit (4.20.0)
80
+ faraday (>= 0.9)
81
+ sawyer (~> 0.8.0, >= 0.5.3)
82
+ open4 (1.3.4)
83
+ parallel (1.20.1)
84
+ parser (3.0.0.0)
85
+ ast (~> 2.4.1)
86
+ pry (0.13.1)
87
+ coderay (~> 1.1)
88
+ method_source (~> 1.0)
89
+ public_suffix (4.0.6)
90
+ rainbow (3.0.0)
91
+ rake (10.5.0)
92
+ rb-fsevent (0.10.4)
93
+ rb-inotify (0.10.1)
94
+ ffi (~> 1.0)
95
+ rchardet (1.8.0)
96
+ regexp_parser (2.0.3)
97
+ rexml (3.2.4)
98
+ rspec (3.10.0)
99
+ rspec-core (~> 3.10.0)
100
+ rspec-expectations (~> 3.10.0)
101
+ rspec-mocks (~> 3.10.0)
102
+ rspec-core (3.10.1)
103
+ rspec-support (~> 3.10.0)
104
+ rspec-expectations (3.10.1)
105
+ diff-lcs (>= 1.2.0, < 2.0)
106
+ rspec-support (~> 3.10.0)
107
+ rspec-mocks (3.10.2)
108
+ diff-lcs (>= 1.2.0, < 2.0)
109
+ rspec-support (~> 3.10.0)
110
+ rspec-support (3.10.2)
111
+ rubocop (1.9.1)
112
+ parallel (~> 1.10)
113
+ parser (>= 3.0.0.0)
114
+ rainbow (>= 2.2.2, < 4.0)
115
+ regexp_parser (>= 1.8, < 3.0)
116
+ rexml
117
+ rubocop-ast (>= 1.2.0, < 2.0)
118
+ ruby-progressbar (~> 1.7)
119
+ unicode-display_width (>= 1.4.0, < 3.0)
120
+ rubocop-ast (1.4.1)
121
+ parser (>= 2.7.1.5)
122
+ ruby-progressbar (1.11.0)
123
+ ruby2_keywords (0.0.4)
124
+ sawyer (0.8.2)
125
+ addressable (>= 2.3.5)
126
+ faraday (> 0.8, < 2.0)
127
+ shellany (0.0.1)
128
+ terminal-table (1.6.0)
129
+ thor (1.1.0)
130
+ unicode-display_width (2.0.0)
131
+ yard (0.9.26)
132
+
133
+ PLATFORMS
134
+ ruby
135
+
136
+ DEPENDENCIES
137
+ bundler (~> 2.0)
138
+ danger-ormolu!
139
+ guard (~> 2.14)
140
+ guard-rspec (~> 4.7)
141
+ listen (= 3.0.7)
142
+ pry
143
+ rake (~> 10.0)
144
+ rspec (~> 3.4)
145
+ rubocop
146
+ yard
147
+
148
+ BUNDLED WITH
149
+ 2.1.4
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2021, Gautier DI FOLCO <gautier.difolco@gmail.com>
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # danger-ormolu
2
+
3
+ A danger plugin for the Haskell code formatter ormolu
4
+
5
+ ## Installation
6
+
7
+ $ gem install danger-ormolu
8
+
9
+ ## Usage
10
+ Be sure to have `ormolu` and `diff` in your `PATH`, include it in your `Gemfile`:
11
+
12
+ ```
13
+ # frozen_string_literal: true
14
+
15
+ source "https://rubygems.org"
16
+
17
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
18
+
19
+ # gem "rails"
20
+ gem 'danger'
21
+ gem 'danger-ormolu'
22
+ ```
23
+
24
+ Finally use this line in your `Dangerfile`:
25
+
26
+ ```
27
+ # get all affected files by the changes in the current diff
28
+ affected_files = git.added_files + git.modified_files
29
+
30
+ # limit files to .hs files
31
+ haskell_files = affected_files.select { |file| file.end_with?('.hs') }
32
+
33
+ ormolu.check haskell_files
34
+ ```
35
+ Methods and attributes from this plugin are available in
36
+ your `Dangerfile` under the `ormolu` namespace.
37
+
38
+ ## Development
39
+
40
+ 1. Clone this repo
41
+ 2. Run `bundle install` to setup dependencies.
42
+ 3. Run `bundle exec rake spec` to run the tests.
43
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
44
+ 5. Make your changes.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: :specs
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,49 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ormolu/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-ormolu'
8
+ spec.version = Ormolu::VERSION
9
+ spec.authors = ['Gautier DI FOLCO']
10
+ spec.email = ['gautier.difolco@gmail.com']
11
+ spec.description = %q{A danger plugin for ormolu}
12
+ spec.summary = %q{A danger plugin for the Haskell code formatter ormolu}
13
+ spec.homepage = 'https://github.com/blackheaven/danger-ormolu'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
22
+
23
+ # General ruby development
24
+ spec.add_development_dependency 'bundler', '~> 2.0'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+
27
+ # Testing support
28
+ spec.add_development_dependency 'rspec', '~> 3.4'
29
+
30
+ # Linting code and docs
31
+ spec.add_development_dependency "rubocop"
32
+ spec.add_development_dependency "yard"
33
+
34
+ # Makes testing easy via `bundle exec guard`
35
+ spec.add_development_dependency 'guard', '~> 2.14'
36
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
37
+
38
+ # If you want to work on older builds of ruby
39
+ spec.add_development_dependency 'listen', '3.0.7'
40
+
41
+ # This gives you the chance to run a REPL inside your tests
42
+ # via:
43
+ #
44
+ # require 'pry'
45
+ # binding.pry
46
+ #
47
+ # This will stop test execution and let you inspect the results
48
+ spec.add_development_dependency 'pry'
49
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ormolu/gem_version'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ormolu/plugin'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ormolu
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Danger
4
+ # Lint haskell files against ormolu formatting
5
+ #
6
+ # @example Ensure the files are correctly formatted
7
+ #
8
+ # ormolu.check files
9
+ #
10
+ # @see blackheaven/danger-ormolu
11
+ # @tags haskell, formatting, ormolu
12
+ #
13
+ class DangerOrmolu < Plugin
14
+ # Check that the files are correctly formatted
15
+ # @param files [Array<String>]
16
+ # @return [void]
17
+ #
18
+ def check(files)
19
+ files
20
+ .each do |file|
21
+ result = `ormolu --mode stdout --check-idempotence "#{file}" | diff "#{file}" -`
22
+ next if result.empty?
23
+
24
+ extract_diffs(result.lines)
25
+ .each do |diff|
26
+ inconsistence(file, diff[:line], diff[:diff])
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def inconsistence(file, line, diff)
34
+ message = "Style error, fix it through \n\n```haskell\n#{diff}\n``` \n"
35
+ warn(message, file: file, line: line)
36
+ end
37
+
38
+ def extract_diffs(lines)
39
+ lines
40
+ .reverse
41
+ .slice_when { |l| l =~ /^\d.*/ }
42
+ .to_a
43
+ .map(&:reverse)
44
+ .reverse
45
+ .map do |chunk|
46
+ { line: chunk.first[/^\d+/].to_i, diff: chunk.flatten }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,16 @@
1
+ module Main where
2
+
3
+ -- | Here we have 'Foo'.
4
+
5
+ data Foo
6
+ =
7
+ -- | One
8
+ Foo
9
+ |
10
+ -- | Two
11
+ Bar Int
12
+ |
13
+ -- | Three
14
+ Baz
15
+ deriving
16
+ (Eq, Show)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('spec_helper', __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerOrmolu do
7
+ it 'should be a plugin' do
8
+ expect(Danger::DangerOrmolu.new(nil)).to be_a Danger::Plugin
9
+ end
10
+
11
+ #
12
+ # You should test your custom attributes and methods here
13
+ #
14
+ describe 'with Dangerfile' do
15
+ before do
16
+ @dangerfile = testing_dangerfile
17
+ @ormolu = @dangerfile.ormolu
18
+ allow(@ormolu.git).to receive(:added_files).and_return([])
19
+ allow(@ormolu.git).to receive(:modified_files).and_return([])
20
+ end
21
+
22
+ # Some examples for writing tests
23
+ # You should replace these with your own.
24
+
25
+ it 'collects Warnings' do
26
+ expect(@ormolu).to receive(:warn).exactly(4).times
27
+ @ormolu.check([File.expand_path('spec/fixtures/HaskellTestFile.hs')])
28
+ end
29
+ end
30
+ end
31
+ end