From 9c1df04756bd900c1ab61e98526ad6eaac8a7216 Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Sat, 13 Apr 2019 16:38:04 +0200 Subject: [PATCH] Welcom pronto-hlint! This is a whole rewrite of pronto-eslint_npm. Forking the pronto-eslint_npm repository to build a runner for hlint haskell linter. --- .gitignore | 4 +- .ruby-version | 2 +- .travis.yml | 17 +- LICENSE | 2 +- README.md | 43 ++--- gems.locked | 71 ++++++++ Gemfile => gems.rb | 0 lib/pronto/eslint_npm.rb | 104 ----------- lib/pronto/eslint_npm/version.rb | 7 - lib/pronto/hlint.rb | 8 + lib/pronto/hlint/runner.rb | 120 +++++++++++++ lib/pronto/hlint/version.rb | 7 + ...eslint_npm.gemspec => pronto-hlint.gemspec | 16 +- spec/fixtures/eslintignore.git/.eslintignore | 2 - spec/fixtures/eslintignore.git/.eslintrc | 7 - spec/fixtures/eslintignore.git/git/HEAD | 1 - spec/fixtures/eslintignore.git/git/config | 7 - spec/fixtures/eslintignore.git/git/index | Bin 353 -> 0 bytes spec/fixtures/eslintignore.git/git/logs/HEAD | 3 - .../git/logs/refs/heads/eslintignore | 2 - .../git/logs/refs/heads/master | 1 - .../2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 | Bin 73 -> 0 bytes .../4b/825dc642cb6eb9a060e54bf8d69288fbee4904 | Bin 15 -> 0 bytes .../5f/fc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 | Bin 185 -> 0 bytes .../69/7ffd3c693fce9abcb871b9b47e2d116e6241d3 | Bin 88 -> 0 bytes .../d4/3de0396c81608113f99f7afd00f7f363e1cae8 | 2 - .../d8/5195b5ff74cc05d121b758f00da43018f53b6f | Bin 42 -> 0 bytes .../ec/7b4537cbd327a580ee44b74ff02fffc74feb46 | Bin 63 -> 0 bytes .../git/refs/heads/eslintignore | 1 - .../eslintignore.git/git/refs/heads/master | 1 - .../eslintignore.git/ignored/ignored.js | 5 - .../eslintignore.git/ignored/not_ignored.js | 5 - spec/fixtures/test.git/.eslintrc | 7 - spec/fixtures/test.git/custom_eslint.sh | 1 - spec/fixtures/test.git/custom_hlint.sh | 3 + spec/fixtures/test.git/git/COMMIT_EDITMSG | 1 + spec/fixtures/test.git/git/HEAD | 2 +- spec/fixtures/test.git/git/config | 2 - spec/fixtures/test.git/git/description | 1 + .../test.git/git/hooks/applypatch-msg.sample | 15 ++ .../test.git/git/hooks/commit-msg.sample | 24 +++ .../git/hooks/fsmonitor-watchman.sample | 114 ++++++++++++ .../test.git/git/hooks/post-update.sample | 8 + .../test.git/git/hooks/pre-applypatch.sample | 14 ++ .../test.git/git/hooks/pre-commit.sample | 49 +++++ .../test.git/git/hooks/pre-push.sample | 53 ++++++ .../test.git/git/hooks/pre-rebase.sample | 169 ++++++++++++++++++ .../test.git/git/hooks/pre-receive.sample | 24 +++ .../git/hooks/prepare-commit-msg.sample | 42 +++++ .../fixtures/test.git/git/hooks/update.sample | 128 +++++++++++++ spec/fixtures/test.git/git/index | Bin 209 -> 217 bytes spec/fixtures/test.git/git/info/exclude | 6 + spec/fixtures/test.git/git/logs/HEAD | 17 +- .../test.git/git/logs/refs/heads/curly | 3 - .../test.git/git/logs/refs/heads/hlint | 2 + .../test.git/git/logs/refs/heads/master | 4 +- .../01/d6dc2234bda69a289104ffdf9667363a2414bd | 2 - .../06/745b4cc11f505bdd1ecc84a744c3802729f92d | Bin 53 -> 0 bytes .../08/cc1f13f1d655a7353040edb359c7f3ab7f8bd4 | Bin 0 -> 132 bytes .../22/2c064befc5a4f3192526863ce449c81bb74924 | Bin 86 -> 0 bytes .../2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 | Bin 73 -> 0 bytes .../37/018e429ad00f0ec961bd218e3dfa6a6e8cc05b | 1 - .../3a/6237c5feacca9a37c36bec5110a1eeb9da703b | Bin 212 -> 0 bytes .../3a/efa89bfb08a4697dc441eed97005eb304364d8 | Bin 57 -> 0 bytes .../45/2143142df8628483f4a2fd4a4bbff9e89ea7a6 | Bin 55 -> 0 bytes .../55/3b8ba14bc0100f71f0bbe45c7ad29a088f7c15 | 1 + .../76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8 | Bin 53 -> 0 bytes .../77/b5c76d003b18b78c41b86e36884ce49f40c259 | Bin 66 -> 0 bytes .../85/e04b1eb1a721d42db51d49e49dfeb8255a5741 | Bin 154 -> 0 bytes .../92/35e9c88c2051d6949febe22fc942365a0b2546 | Bin 86 -> 0 bytes .../93/1004157205727e6a47586feaed0473c6ddbd66 | Bin 154 -> 0 bytes .../9f/c2abdd0895100b5876bc346dad6bbfb39e9324 | Bin 53 -> 0 bytes .../c8/0c26814ee76057a8493b791e6e1a623f693e97 | Bin 0 -> 58 bytes .../cf/e8bc15022f8b4d3cea89bc20abb13f985feeb0 | Bin 60 -> 0 bytes .../d0/80b4f440e8a87be90677df855a139a36bd2dc3 | Bin 46 -> 0 bytes .../dd/e5c6b931572a74d0824ad8268e826ba18647b4 | Bin 0 -> 146 bytes .../e4/38134aac40ce86789d552f1bdada6582a987f6 | 1 - .../f3/7efccc1cef20309de28bfbdd16d0c4afb9d550 | 3 - .../f6/e267486c6b9d0f50a690c894df5e981e31c1b0 | Bin 0 -> 96 bytes .../f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0 | Bin 179 -> 0 bytes spec/fixtures/test.git/git/refs/heads/curly | 1 - spec/fixtures/test.git/git/refs/heads/hlint | 1 + spec/fixtures/test.git/git/refs/heads/master | 2 +- spec/fixtures/test.git/hello.js | 7 - spec/fixtures/test.git/pronto.hs | 11 ++ spec/fixtures/test.git/world.es6 | 5 - spec/pronto/eslint_spec.rb | 163 ----------------- spec/pronto/hlint_spec.rb | 138 ++++++++++++++ spec/spec_helper.rb | 9 +- 89 files changed, 1055 insertions(+), 417 deletions(-) create mode 100644 gems.locked rename Gemfile => gems.rb (100%) delete mode 100644 lib/pronto/eslint_npm.rb delete mode 100644 lib/pronto/eslint_npm/version.rb create mode 100644 lib/pronto/hlint.rb create mode 100644 lib/pronto/hlint/runner.rb create mode 100644 lib/pronto/hlint/version.rb rename pronto-eslint_npm.gemspec => pronto-hlint.gemspec (62%) delete mode 100644 spec/fixtures/eslintignore.git/.eslintignore delete mode 100644 spec/fixtures/eslintignore.git/.eslintrc delete mode 100644 spec/fixtures/eslintignore.git/git/HEAD delete mode 100644 spec/fixtures/eslintignore.git/git/config delete mode 100644 spec/fixtures/eslintignore.git/git/index delete mode 100644 spec/fixtures/eslintignore.git/git/logs/HEAD delete mode 100644 spec/fixtures/eslintignore.git/git/logs/refs/heads/eslintignore delete mode 100644 spec/fixtures/eslintignore.git/git/logs/refs/heads/master delete mode 100644 spec/fixtures/eslintignore.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 delete mode 100644 spec/fixtures/eslintignore.git/git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 delete mode 100644 spec/fixtures/eslintignore.git/git/objects/5f/fc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 delete mode 100644 spec/fixtures/eslintignore.git/git/objects/69/7ffd3c693fce9abcb871b9b47e2d116e6241d3 delete mode 100644 spec/fixtures/eslintignore.git/git/objects/d4/3de0396c81608113f99f7afd00f7f363e1cae8 delete mode 100644 spec/fixtures/eslintignore.git/git/objects/d8/5195b5ff74cc05d121b758f00da43018f53b6f delete mode 100644 spec/fixtures/eslintignore.git/git/objects/ec/7b4537cbd327a580ee44b74ff02fffc74feb46 delete mode 100644 spec/fixtures/eslintignore.git/git/refs/heads/eslintignore delete mode 100644 spec/fixtures/eslintignore.git/git/refs/heads/master delete mode 100644 spec/fixtures/eslintignore.git/ignored/ignored.js delete mode 100644 spec/fixtures/eslintignore.git/ignored/not_ignored.js delete mode 100644 spec/fixtures/test.git/.eslintrc delete mode 100755 spec/fixtures/test.git/custom_eslint.sh create mode 100755 spec/fixtures/test.git/custom_hlint.sh create mode 100644 spec/fixtures/test.git/git/COMMIT_EDITMSG create mode 100644 spec/fixtures/test.git/git/description create mode 100755 spec/fixtures/test.git/git/hooks/applypatch-msg.sample create mode 100755 spec/fixtures/test.git/git/hooks/commit-msg.sample create mode 100755 spec/fixtures/test.git/git/hooks/fsmonitor-watchman.sample create mode 100755 spec/fixtures/test.git/git/hooks/post-update.sample create mode 100755 spec/fixtures/test.git/git/hooks/pre-applypatch.sample create mode 100755 spec/fixtures/test.git/git/hooks/pre-commit.sample create mode 100755 spec/fixtures/test.git/git/hooks/pre-push.sample create mode 100755 spec/fixtures/test.git/git/hooks/pre-rebase.sample create mode 100755 spec/fixtures/test.git/git/hooks/pre-receive.sample create mode 100755 spec/fixtures/test.git/git/hooks/prepare-commit-msg.sample create mode 100755 spec/fixtures/test.git/git/hooks/update.sample create mode 100644 spec/fixtures/test.git/git/info/exclude delete mode 100644 spec/fixtures/test.git/git/logs/refs/heads/curly create mode 100644 spec/fixtures/test.git/git/logs/refs/heads/hlint delete mode 100644 spec/fixtures/test.git/git/objects/01/d6dc2234bda69a289104ffdf9667363a2414bd delete mode 100644 spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92d create mode 100644 spec/fixtures/test.git/git/objects/08/cc1f13f1d655a7353040edb359c7f3ab7f8bd4 delete mode 100644 spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924 delete mode 100644 spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 delete mode 100644 spec/fixtures/test.git/git/objects/37/018e429ad00f0ec961bd218e3dfa6a6e8cc05b delete mode 100644 spec/fixtures/test.git/git/objects/3a/6237c5feacca9a37c36bec5110a1eeb9da703b delete mode 100644 spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8 delete mode 100644 spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6 create mode 100644 spec/fixtures/test.git/git/objects/55/3b8ba14bc0100f71f0bbe45c7ad29a088f7c15 delete mode 100644 spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8 delete mode 100644 spec/fixtures/test.git/git/objects/77/b5c76d003b18b78c41b86e36884ce49f40c259 delete mode 100644 spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741 delete mode 100644 spec/fixtures/test.git/git/objects/92/35e9c88c2051d6949febe22fc942365a0b2546 delete mode 100644 spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66 delete mode 100644 spec/fixtures/test.git/git/objects/9f/c2abdd0895100b5876bc346dad6bbfb39e9324 create mode 100644 spec/fixtures/test.git/git/objects/c8/0c26814ee76057a8493b791e6e1a623f693e97 delete mode 100644 spec/fixtures/test.git/git/objects/cf/e8bc15022f8b4d3cea89bc20abb13f985feeb0 delete mode 100644 spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3 create mode 100644 spec/fixtures/test.git/git/objects/dd/e5c6b931572a74d0824ad8268e826ba18647b4 delete mode 100644 spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6 delete mode 100644 spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d550 create mode 100644 spec/fixtures/test.git/git/objects/f6/e267486c6b9d0f50a690c894df5e981e31c1b0 delete mode 100644 spec/fixtures/test.git/git/objects/f7/eb73cae47464f2d235a1d014c4617ad2aa0cb0 delete mode 100644 spec/fixtures/test.git/git/refs/heads/curly create mode 100644 spec/fixtures/test.git/git/refs/heads/hlint delete mode 100644 spec/fixtures/test.git/hello.js create mode 100644 spec/fixtures/test.git/pronto.hs delete mode 100644 spec/fixtures/test.git/world.es6 delete mode 100644 spec/pronto/eslint_spec.rb create mode 100644 spec/pronto/hlint_spec.rb diff --git a/.gitignore b/.gitignore index f783885..743adc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ pkg/* *.gem .bundle -.DS_Store -Gemfile.lock -.byebug_history +gems.lock diff --git a/.ruby-version b/.ruby-version index 6a6a3d8..097a15a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6.1 +2.6.2 diff --git a/.travis.yml b/.travis.yml index dab13ac..74e9f59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,8 @@ --- -sudo: required -dist: xenial -language: ruby -before_install: - - gem update --system +language: nix before_script: - - npm install -g eslint -rvm: - - 2.3.8 - - 2.4.4 - - 2.5.3 - - 2.6.1 + - nix-env -iA nixpkgs.hlint nixpkgs.ruby_2_6 + - gem install bundler +script: + - bundle install + - bundle exec rake spec diff --git a/LICENSE b/LICENSE index baecb15..91bb5a8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2016 Mindaugas MozÅ«ras +Copyright (c) 2019 Fretlink Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 508080b..7cec7d6 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,39 @@ -# Pronto runner for ESLint (using eslint from npm) +# Pronto runner for Hlint -[![Code Climate](https://codeclimate.com/github/doits/pronto-eslint_npm.svg)](https://codeclimate.com/github/doits/pronto-eslint_npm) -[![Build Status](https://travis-ci.org/doits/pronto-eslint_npm.svg?branch=master)](https://travis-ci.org/doits/pronto-eslint_npm) -[![Gem Version](https://badge.fury.io/rb/pronto-eslint_npm.svg)](http://badge.fury.io/rb/pronto-eslint_npm) +[![Build Status](https://travis-ci.org/fretlink/pronto-hlint.svg?branch=master)](https://travis-ci.org/fretlink/pronto-hlint) +[![Gem Version](https://badge.fury.io/rb/pronto-hlint.svg)](http://badge.fury.io/rb/pronto-hlint) -Pronto runner for [ESlint](http://eslint.org), pluggable linting utility for JavaScript and JSX. [What is Pronto?](https://github.com/mmozuras/pronto) - -Uses official eslint executable installed by `npm` in contrast to [pronto-eslint][pronto-eslint]. - -[pronto-eslint]: https://github.com/mmozuras/pronto-eslint +Pronto runner for [Hlint](https://hackage.haskell.org/package/hlint), pluggable linting utility for Haskell. [What is Pronto?](https://github.com/mmozuras/pronto) ## Prerequisites -You'll need to install [eslint by yourself with npm][eslint-install]. If `eslint` is in your `PATH`, everything will simply work, otherwise you have to provide pronto-eslint-npm your custom executable path (see [below](#configuration-of-eslintnpm)). - -[eslint-install]: http://eslint.org/docs/user-guide/getting-started +You'll need to install [hlint by yourself with cabal or stack][hlint-install]. If `hlint` is in your `PATH`, everything will simply work, otherwise you have to provide pronto-hlint your custom executable path (see [below](#configuration-of-hlint)). -## Configuration of ESLint +[hlint-install]: https://github.com/ndmitchell/hlint#installing-and-running-hlint -Configuring ESLint via [.eslintrc and consorts][eslintrc] and excludes via [.eslintignore][eslintignore] will work just fine with pronto-eslint-npm. +## Configuration of Hlint -[eslintrc]: http://eslint.org/docs/user-guide/configuring#configuration-file-formats +Configuring Hlint via [.hlint.yaml][.hlint.yaml] will work just fine with pronto-hlint. -[eslintignore]: http://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories +[.hlint.yaml]: https://github.com/ndmitchell/hlint#customizing-the-hints -## Configuration of ESLintNPM +## Configuration of Pronto-Hlint -pronto-eslint-npm can be configured by placing a `.pronto_eslint_npm.yml` inside the directory where pronto is run. +pronto-hlint can be configured by placing a `.pronto_hlint.yml` inside the directory where pronto will run. Following options are available: | Option | Meaning | Default | | ----------------- | ---------------------------------------------------------------------------------------- | ----------------------------------- | -| eslint_executable | ESLint executable to call. | `eslint` (calls `eslint` in `PATH`) | -| files_to_lint | What files to lint. Absolute path of offending file will be matched against this Regexp. | `(\.js|\.es6)$` | -| cmd_line_opts | Command line options to pass to eslint when running | '' | +| hlint_executable | Hlint executable to call. | `hlint` (calls `hlint` in `PATH`) | +| files_to_lint | What files to lint. Absolute path of offending file will be matched against this Regexp. | `(\.hs)$` | +| cmd_line_opts | Command line options to pass to hlint when running | `` | -Example configuration to call custom eslint executable and only lint files ending with `.my_custom_extension`: +Example configuration to call custom hlint executable and only lint files ending with `.my_custom_extension`: ```yaml -# .pronto_eslint_npm.yml -eslint_executable: '/my/custom/node/path/.bin/eslint' +# .pronto_hlint.yml +hlint_executable: '/my/custom/path/.bin/hlint' files_to_lint: '\.my_custom_extension$' -cmd_line_opts: '--ext .html,.js,.es6' +cmd_line_opts: '-j $(nproc) --typecheck' ``` diff --git a/gems.locked b/gems.locked new file mode 100644 index 0000000..9a5d599 --- /dev/null +++ b/gems.locked @@ -0,0 +1,71 @@ +PATH + remote: . + specs: + pronto-hlint (0.1.0) + pronto (~> 0.10.0) + +GEM + remote: https://rubygems.org/ + specs: + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + byebug (11.0.1) + diff-lcs (1.3) + faraday (0.15.4) + multipart-post (>= 1.2, < 3) + gitlab (4.10.0) + httparty (~> 0.14, >= 0.14.0) + terminal-table (~> 1.5, >= 1.5.1) + httparty (0.16.4) + mime-types (~> 3.0) + multi_xml (>= 0.5.2) + mime-types (3.2.2) + mime-types-data (~> 3.2015) + mime-types-data (3.2019.0331) + multi_xml (0.6.0) + multipart-post (2.0.0) + octokit (4.14.0) + sawyer (~> 0.8.0, >= 0.5.3) + pronto (0.10.0) + gitlab (~> 4.0, >= 4.0.0) + httparty (>= 0.13.7) + octokit (~> 4.7, >= 4.7.0) + rainbow (>= 2.2, < 4.0) + rugged (~> 0.24, >= 0.23.0) + thor (~> 0.20.0) + public_suffix (3.0.3) + rainbow (3.0.0) + rake (12.3.2) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + rugged (0.28.1) + sawyer (0.8.1) + addressable (>= 2.3.5, < 2.6) + faraday (~> 0.8, < 1.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thor (0.20.3) + unicode-display_width (1.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + byebug (>= 9) + pronto-hlint! + rake (>= 11.0, < 13) + rspec (~> 3.4) + +BUNDLED WITH + 2.0.1 diff --git a/Gemfile b/gems.rb similarity index 100% rename from Gemfile rename to gems.rb diff --git a/lib/pronto/eslint_npm.rb b/lib/pronto/eslint_npm.rb deleted file mode 100644 index 6a9c00c..0000000 --- a/lib/pronto/eslint_npm.rb +++ /dev/null @@ -1,104 +0,0 @@ -# frozen_string_literal: true - -require 'pronto' -require 'shellwords' - -module Pronto - class ESLintNpm < Runner - CONFIG_FILE = '.pronto_eslint_npm.yml'.freeze - CONFIG_KEYS = %w[eslint_executable files_to_lint cmd_line_opts].freeze - - attr_writer :eslint_executable, :cmd_line_opts - - def eslint_executable - @eslint_executable || 'eslint' - end - - def files_to_lint - @files_to_lint || /(\.js|\.es6)$/ - end - - def cmd_line_opts - @cmd_line_opts || '' - end - - def files_to_lint=(regexp) - @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp) - end - - def config_options - @config_options ||= - begin - config_file = File.join(repo_path, CONFIG_FILE) - File.exist?(config_file) && YAML.load_file(config_file) || {} - end - end - - def read_config - config_options.each do |key, val| - next unless CONFIG_KEYS.include?(key.to_s) - send("#{key}=", val) - end - end - - def run - return [] if !@patches || @patches.count.zero? - - read_config - - @patches - .select { |patch| patch.additions > 0 } - .select { |patch| js_file?(patch.new_file_full_path) } - .map { |patch| inspect(patch) } - .flatten.compact - end - - private - - def repo_path - @repo_path ||= @patches.first.repo.path - end - - def inspect(patch) - offences = run_eslint(patch) - clean_up_eslint_output(offences) - .map do |offence| - patch - .added_lines - .select { |line| line.new_lineno == offence['line'] } - .map { |line| new_message(offence, line) } - end - end - - def new_message(offence, line) - path = line.patch.delta.new_file[:path] - level = :warning - - Message.new(path, line, level, offence['message'], nil, self.class) - end - - def js_file?(path) - files_to_lint =~ path.to_s - end - - def run_eslint(patch) - Dir.chdir(repo_path) do - JSON.parse `#{eslint_command_line(patch.new_file_full_path.to_s)}` - end - end - - def eslint_command_line(path) - "#{eslint_executable} #{cmd_line_opts} #{Shellwords.escape(path)} -f json" - end - - def clean_up_eslint_output(output) - # 1. Filter out offences without a warning or error - # 2. Get the messages for that file - # 3. Ignore errors without a line number for now - output - .select { |offence| offence['errorCount'] + offence['warningCount'] > 0 } - .map { |offence| offence['messages'] } - .flatten.select { |offence| offence['line'] } - end - end -end diff --git a/lib/pronto/eslint_npm/version.rb b/lib/pronto/eslint_npm/version.rb deleted file mode 100644 index e3683f4..0000000 --- a/lib/pronto/eslint_npm/version.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -module Pronto - module ESLintNpmVersion - VERSION = '0.10.0'.freeze - end -end diff --git a/lib/pronto/hlint.rb b/lib/pronto/hlint.rb new file mode 100644 index 0000000..daf1029 --- /dev/null +++ b/lib/pronto/hlint.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require 'pronto/hlint/runner' + +module Pronto + module Hlint + end +end diff --git a/lib/pronto/hlint/runner.rb b/lib/pronto/hlint/runner.rb new file mode 100644 index 0000000..e334860 --- /dev/null +++ b/lib/pronto/hlint/runner.rb @@ -0,0 +1,120 @@ +# frozen_string_literal: true + +require 'pronto' +require 'shellwords' + +module Pronto + module Hlint + class Runner < Pronto::Runner + CONFIG_FILE = '.pronto_hlint.yml'.freeze + CONFIG_KEYS = %w[hlint_executable files_to_lint cmd_line_opts].freeze + + attr_writer :hlint_executable, :cmd_line_opts + + def hlint_executable + @hlint_executable || 'hlint' + end + + def files_to_lint + @files_to_lint || /(\.hs)$/ + end + + def cmd_line_opts + @cmd_line_opts || '' + end + + def files_to_lint=(regexp) + @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp) + end + + def config_options + @config_options ||= + begin + config_file = File.join(repo_path, CONFIG_FILE) + File.exist?(config_file) && YAML.load_file(config_file) || {} + end + end + + def read_config + config_options.each do |key, val| + next unless CONFIG_KEYS.include?(key.to_s) + send("#{key}=", val) + end + end + + def run + return [] if !@patches || @patches.count.zero? + + read_config + + @patches + .select { |patch| patch.additions > 0 } + .select { |patch| hs_file?(patch.new_file_full_path) } + .map { |patch| inspect(patch) } + .flatten.compact + end + + private + + def repo_path + @repo_path ||= @patches.first.repo.path + end + + def inspect(patch) + offences = run_hlint(patch) + offences + .map do |offence| + patch + .added_lines + .select { |line| (offence['startLine']..offence['endLine']).include?(line.new_lineno) } + .map { |line| new_message(offence, line) } + end + end + + def new_message(offence, line) + path = line.patch.delta.new_file[:path] + level = hlint_severity_to_pronto_level(offence['severity']) || :warning + + text = <<~EOF + #{offence['severity']} offence detected by Hlint. Hint is: `#{offence['hint']}`. + + Consider changing the code from + ``` + #{offence['from']} + ``` + to + ``` + #{offence['to']} + ``` + EOF + + Message.new(path, line, level, text, nil, self.class) + end + + def hlint_severity_to_pronto_level(severity) + case severity + when "Error" + :error + when "Warning" + :warning + when "Suggestion" + :info + end + end + + def hs_file?(path) + files_to_lint =~ path.to_s + end + + def run_hlint(patch) + Dir.chdir(repo_path) do + JSON.parse `#{hlint_command_line(patch.new_file_full_path.to_s)}` + end + end + + def hlint_command_line(path) + "#{hlint_executable} #{cmd_line_opts} #{Shellwords.escape(path)} --json" + end + end + end +end diff --git a/lib/pronto/hlint/version.rb b/lib/pronto/hlint/version.rb new file mode 100644 index 0000000..0b9bd5a --- /dev/null +++ b/lib/pronto/hlint/version.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Pronto + module Hlint + VERSION = '0.1.0'.freeze + end +end diff --git a/pronto-eslint_npm.gemspec b/pronto-hlint.gemspec similarity index 62% rename from pronto-eslint_npm.gemspec rename to pronto-hlint.gemspec index 2a70f2f..2d56792 100644 --- a/pronto-eslint_npm.gemspec +++ b/pronto-hlint.gemspec @@ -1,17 +1,17 @@ # frozen_string_literal: true $LOAD_PATH.push File.expand_path('lib', __dir__) -require 'pronto/eslint_npm/version' +require 'pronto/hlint/version' Gem::Specification.new do |s| - s.name = 'pronto-eslint_npm' - s.version = Pronto::ESLintNpmVersion::VERSION + s.name = 'pronto-hlint' + s.version = Pronto::Hlint::VERSION s.platform = Gem::Platform::RUBY - s.authors = ['Markus Doits', 'Mindaugas MozÅ«ras'] - s.email = 'markus.doits@gmail.com' - s.homepage = 'https://github.com/doits/pronto-eslint_npm' + s.authors = ['Paul Bonaud'] + s.email = 'paul.bonaud@fretlink.com' + s.homepage = 'https://github.com/fretlink/pronto-hlint' s.summary = <<-EOF - Pronto runner for ESLint, pluggable linting utility for JavaScript and JSX + Pronto runner for Hlint, pluggable linting utility for Haskell EOF s.licenses = ['MIT'] @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.files = `git ls-files -z`.split("\x0").select { |f| f.match(%r{^(lib/|(LICENSE|README.md)$)}) } s.extra_rdoc_files = ['LICENSE', 'README.md'] s.require_paths = ['lib'] - s.requirements << 'eslint (in PATH)' + s.requirements << 'hlint (in PATH)' s.add_dependency('pronto', '~> 0.10.0') s.add_development_dependency('byebug', '>= 9') diff --git a/spec/fixtures/eslintignore.git/.eslintignore b/spec/fixtures/eslintignore.git/.eslintignore deleted file mode 100644 index d85195b..0000000 --- a/spec/fixtures/eslintignore.git/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -ignored/**/*.js -!ignored/not_ignored.js diff --git a/spec/fixtures/eslintignore.git/.eslintrc b/spec/fixtures/eslintignore.git/.eslintrc deleted file mode 100644 index f94ba96..0000000 --- a/spec/fixtures/eslintignore.git/.eslintrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "env": { - "browser": true, - "es6": true - }, - "extends": "eslint:recommended" -} diff --git a/spec/fixtures/eslintignore.git/git/HEAD b/spec/fixtures/eslintignore.git/git/HEAD deleted file mode 100644 index fac958f..0000000 --- a/spec/fixtures/eslintignore.git/git/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/eslintignore diff --git a/spec/fixtures/eslintignore.git/git/config b/spec/fixtures/eslintignore.git/git/config deleted file mode 100644 index 6c9406b..0000000 --- a/spec/fixtures/eslintignore.git/git/config +++ /dev/null @@ -1,7 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = false - logallrefupdates = true - ignorecase = true - precomposeunicode = true diff --git a/spec/fixtures/eslintignore.git/git/index b/spec/fixtures/eslintignore.git/git/index deleted file mode 100644 index 8c5575c45a900a3003f8de90de5049d489f859bb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 353 zcmZ?q402{*U|<4b=J083Wk8w%Ml&)nurMV%9$;W-T*AP>_!TH60>m0O0;g{MUvh@^ zqT=?554=kZB)(ebGw|xA7UyKa)fGNQ~CgPEI`UlNaMc1Vz`E6`j^ z24e+7uFU$sHktP4X6@NgxN}RLu3%o0<7KFF1|tOnt~b@L=BF>KFKu||vfclK{{Q3t cuiXL<7-n2Krf|Bm$hdd|`@fbwuE&l50Lqtb-2eap diff --git a/spec/fixtures/eslintignore.git/git/logs/HEAD b/spec/fixtures/eslintignore.git/git/logs/HEAD deleted file mode 100644 index 8750baa..0000000 --- a/spec/fixtures/eslintignore.git/git/logs/HEAD +++ /dev/null @@ -1,3 +0,0 @@ -0000000000000000000000000000000000000000 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits 1469450052 +0200 commit (initial): empty init commit -d43de0396c81608113f99f7afd00f7f363e1cae8 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits 1469450062 +0200 checkout: moving from master to eslintignore -d43de0396c81608113f99f7afd00f7f363e1cae8 5ffc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 Markus Doits 1469450067 +0200 commit: add .eslintignore and files with errors diff --git a/spec/fixtures/eslintignore.git/git/logs/refs/heads/eslintignore b/spec/fixtures/eslintignore.git/git/logs/refs/heads/eslintignore deleted file mode 100644 index 3467ecc..0000000 --- a/spec/fixtures/eslintignore.git/git/logs/refs/heads/eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -0000000000000000000000000000000000000000 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits 1469450062 +0200 branch: Created from HEAD -d43de0396c81608113f99f7afd00f7f363e1cae8 5ffc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 Markus Doits 1469450067 +0200 commit: add .eslintignore and files with errors diff --git a/spec/fixtures/eslintignore.git/git/logs/refs/heads/master b/spec/fixtures/eslintignore.git/git/logs/refs/heads/master deleted file mode 100644 index 8105749..0000000 --- a/spec/fixtures/eslintignore.git/git/logs/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 d43de0396c81608113f99f7afd00f7f363e1cae8 Markus Doits 1469450052 +0200 commit (initial): empty init commit diff --git a/spec/fixtures/eslintignore.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 b/spec/fixtures/eslintignore.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 deleted file mode 100644 index f5fbdc534df59a48a106d6141541e9cee9d560bf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 73 zcmV-P0Ji^l0ZYosPf{>5XGkl}OD@UG&r|S7&B@6R&o9bJ(a1~8P1WS8=28HH%rpg! fwETQc1t6iVZ4DMn%t5j#GvtFn>c#`^RWHE3w?51RMtxhQoHt)? diff --git a/spec/fixtures/eslintignore.git/git/objects/69/7ffd3c693fce9abcb871b9b47e2d116e6241d3 b/spec/fixtures/eslintignore.git/git/objects/69/7ffd3c693fce9abcb871b9b47e2d116e6241d3 deleted file mode 100644 index c23a96f6f45708f419e891b26c9acf506ed9c567..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 88 zcmV-e0H^AWiT`_Ff%bx&`T}O$;>OsOwY?NN@chaICbm)k~6Fq6}Lxx u;9X)M@zpxt!~h5sAPQ0#-c-AqpT4ZVwBeo0cK;9h|Bw5>b^`zk(js$3YA5CZ diff --git a/spec/fixtures/eslintignore.git/git/objects/d4/3de0396c81608113f99f7afd00f7f363e1cae8 b/spec/fixtures/eslintignore.git/git/objects/d4/3de0396c81608113f99f7afd00f7f363e1cae8 deleted file mode 100644 index e3c829c..0000000 --- a/spec/fixtures/eslintignore.git/git/objects/d4/3de0396c81608113f99f7afd00f7f363e1cae8 +++ /dev/null @@ -1,2 +0,0 @@ -x¥K -Â0@]ç³Ê&!n=D>S mZI¦ o¯Ö#¸|›÷xi­µh´iÌ@Ñi““%¢åèZdCqtÙzíÜ™É#©°ÉcmpmÚ:ÜÖ"Îu§!éڅç™)ib2_àD֓A4Ž¨UÚëÂÿzק¼ ,Ÿ•ŸS½…ïEµ \ No newline at end of file diff --git a/spec/fixtures/eslintignore.git/git/objects/d8/5195b5ff74cc05d121b758f00da43018f53b6f b/spec/fixtures/eslintignore.git/git/objects/d8/5195b5ff74cc05d121b758f00da43018f53b6f deleted file mode 100644 index ee9657e79930394355b20b26de891cef24308244..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 42 zcmV+_0M-9^0ZYosPf{>3V8~3*%P&ez(bv+_*V4->=2CCy+ AHUIzs diff --git a/spec/fixtures/eslintignore.git/git/objects/ec/7b4537cbd327a580ee44b74ff02fffc74feb46 b/spec/fixtures/eslintignore.git/git/objects/ec/7b4537cbd327a580ee44b74ff02fffc74feb46 deleted file mode 100644 index 9a642e0fb02cc0638938d8cba7277dc7562e9bea..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 63 zcmV-F0Korv0V^p=O;xZkU@$Z=Ff%bx$V|`6FG@|(%PMBjm7baQZ{yswsCm)bmhOEb VpkS5p9jYoXza*Z3N&tLVB9CO&9PI!A diff --git a/spec/fixtures/eslintignore.git/git/refs/heads/eslintignore b/spec/fixtures/eslintignore.git/git/refs/heads/eslintignore deleted file mode 100644 index d02562a..0000000 --- a/spec/fixtures/eslintignore.git/git/refs/heads/eslintignore +++ /dev/null @@ -1 +0,0 @@ -5ffc9b3c7f8e8d8f2e8c91cb69c9698405d1ca53 diff --git a/spec/fixtures/eslintignore.git/git/refs/heads/master b/spec/fixtures/eslintignore.git/git/refs/heads/master deleted file mode 100644 index 5dcf161..0000000 --- a/spec/fixtures/eslintignore.git/git/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -d43de0396c81608113f99f7afd00f7f363e1cae8 diff --git a/spec/fixtures/eslintignore.git/ignored/ignored.js b/spec/fixtures/eslintignore.git/ignored/ignored.js deleted file mode 100644 index 2d1b996..0000000 --- a/spec/fixtures/eslintignore.git/ignored/ignored.js +++ /dev/null @@ -1,5 +0,0 @@ -function HelloWorld(name) -{ - if (foo) foo++; - alert(name); -} diff --git a/spec/fixtures/eslintignore.git/ignored/not_ignored.js b/spec/fixtures/eslintignore.git/ignored/not_ignored.js deleted file mode 100644 index 2d1b996..0000000 --- a/spec/fixtures/eslintignore.git/ignored/not_ignored.js +++ /dev/null @@ -1,5 +0,0 @@ -function HelloWorld(name) -{ - if (foo) foo++; - alert(name); -} diff --git a/spec/fixtures/test.git/.eslintrc b/spec/fixtures/test.git/.eslintrc deleted file mode 100644 index f94ba96..0000000 --- a/spec/fixtures/test.git/.eslintrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "env": { - "browser": true, - "es6": true - }, - "extends": "eslint:recommended" -} diff --git a/spec/fixtures/test.git/custom_eslint.sh b/spec/fixtures/test.git/custom_eslint.sh deleted file mode 100755 index 54fafdc..0000000 --- a/spec/fixtures/test.git/custom_eslint.sh +++ /dev/null @@ -1 +0,0 @@ -printf 'custom eslint called' diff --git a/spec/fixtures/test.git/custom_hlint.sh b/spec/fixtures/test.git/custom_hlint.sh new file mode 100755 index 0000000..c80c268 --- /dev/null +++ b/spec/fixtures/test.git/custom_hlint.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "hlint called!" diff --git a/spec/fixtures/test.git/git/COMMIT_EDITMSG b/spec/fixtures/test.git/git/COMMIT_EDITMSG new file mode 100644 index 0000000..d788b46 --- /dev/null +++ b/spec/fixtures/test.git/git/COMMIT_EDITMSG @@ -0,0 +1 @@ +Add hs files with hlint errors diff --git a/spec/fixtures/test.git/git/HEAD b/spec/fixtures/test.git/git/HEAD index c15524d..feb5fdb 100644 --- a/spec/fixtures/test.git/git/HEAD +++ b/spec/fixtures/test.git/git/HEAD @@ -1 +1 @@ -ref: refs/heads/curly +ref: refs/heads/hlint diff --git a/spec/fixtures/test.git/git/config b/spec/fixtures/test.git/git/config index 6c9406b..515f483 100644 --- a/spec/fixtures/test.git/git/config +++ b/spec/fixtures/test.git/git/config @@ -3,5 +3,3 @@ filemode = true bare = false logallrefupdates = true - ignorecase = true - precomposeunicode = true diff --git a/spec/fixtures/test.git/git/description b/spec/fixtures/test.git/git/description new file mode 100644 index 0000000..498b267 --- /dev/null +++ b/spec/fixtures/test.git/git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/spec/fixtures/test.git/git/hooks/applypatch-msg.sample b/spec/fixtures/test.git/git/hooks/applypatch-msg.sample new file mode 100755 index 0000000..a5d7b84 --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/applypatch-msg.sample @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, rename this file to "applypatch-msg". + +. git-sh-setup +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff --git a/spec/fixtures/test.git/git/hooks/commit-msg.sample b/spec/fixtures/test.git/git/hooks/commit-msg.sample new file mode 100755 index 0000000..b58d118 --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/spec/fixtures/test.git/git/hooks/fsmonitor-watchman.sample b/spec/fixtures/test.git/git/hooks/fsmonitor-watchman.sample new file mode 100755 index 0000000..e673bb3 --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/fsmonitor-watchman.sample @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 1) and a time in nanoseconds +# formatted as a string and outputs to stdout all files that have been +# modified since the given time. Paths must be relative to the root of +# the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $time) = @ARGV; + +# Check the hook interface version + +if ($version == 1) { + # convert nanoseconds to seconds + $time = int $time / 1000000000; +} else { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree; +if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $git_work_tree = Win32::GetCwd(); + $git_work_tree =~ tr/\\/\//; +} else { + require Cwd; + $git_work_tree = Cwd::cwd(); +} + +my $retry = 1; + +launch_watchman(); + +sub launch_watchman { + + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $time but were not transient (ie created after + # $time but no longer exist). + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. Then we're using the "expression" term to + # further constrain the results. + # + # The category of transient files that we want to ignore will have a + # creation clock (cclock) newer than $time_t value and will also not + # currently exist. + + my $query = <<" END"; + ["query", "$git_work_tree", { + "since": $time, + "fields": ["name"], + "expression": ["not", ["allof", ["since", $time, "cclock"], ["not", "exists"]]] + }] + END + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; }; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + my $json_pkg; + eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; + } or do { + require JSON::PP; + $json_pkg = "JSON::PP"; + }; + + my $o = $json_pkg->new->utf8->decode($response); + + if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { + print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; + $retry--; + qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + print "/\0"; + eval { launch_watchman() }; + exit 0; + } + + die "Watchman: $o->{error}.\n" . + "Falling back to scanning...\n" if $o->{error}; + + binmode STDOUT, ":utf8"; + local $, = "\0"; + print @{$o->{files}}; +} diff --git a/spec/fixtures/test.git/git/hooks/post-update.sample b/spec/fixtures/test.git/git/hooks/post-update.sample new file mode 100755 index 0000000..ec17ec1 --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff --git a/spec/fixtures/test.git/git/hooks/pre-applypatch.sample b/spec/fixtures/test.git/git/hooks/pre-applypatch.sample new file mode 100755 index 0000000..4142082 --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff --git a/spec/fixtures/test.git/git/hooks/pre-commit.sample b/spec/fixtures/test.git/git/hooks/pre-commit.sample new file mode 100755 index 0000000..6a75641 --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/pre-commit.sample @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/spec/fixtures/test.git/git/hooks/pre-push.sample b/spec/fixtures/test.git/git/hooks/pre-push.sample new file mode 100755 index 0000000..6187dbf --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/pre-push.sample @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +z40=0000000000000000000000000000000000000000 + +while read local_ref local_sha remote_ref remote_sha +do + if [ "$local_sha" = $z40 ] + then + # Handle delete + : + else + if [ "$remote_sha" = $z40 ] + then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + # Check for WIP commit + commit=`git rev-list -n 1 --grep '^WIP' "$range"` + if [ -n "$commit" ] + then + echo >&2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff --git a/spec/fixtures/test.git/git/hooks/pre-rebase.sample b/spec/fixtures/test.git/git/hooks/pre-rebase.sample new file mode 100755 index 0000000..6cbef5c --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff --git a/spec/fixtures/test.git/git/hooks/pre-receive.sample b/spec/fixtures/test.git/git/hooks/pre-receive.sample new file mode 100755 index 0000000..a1fd29e --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/pre-receive.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff --git a/spec/fixtures/test.git/git/hooks/prepare-commit-msg.sample b/spec/fixtures/test.git/git/hooks/prepare-commit-msg.sample new file mode 100755 index 0000000..10fa14c --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/prepare-commit-msg.sample @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff --git a/spec/fixtures/test.git/git/hooks/update.sample b/spec/fixtures/test.git/git/hooks/update.sample new file mode 100755 index 0000000..80ba941 --- /dev/null +++ b/spec/fixtures/test.git/git/hooks/update.sample @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block unannotated tags from entering. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +# +# To enable this hook, rename this file to "update". +# +# Config +# ------ +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. +# hooks.denycreatebranch +# This boolean sets whether remotely creating branches will be denied +# in the repository. By default this is allowed. +# + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --bool hooks.allowunannotated) +allowdeletebranch=$(git config --bool hooks.allowdeletebranch) +denycreatebranch=$(git config --bool hooks.denycreatebranch) +allowdeletetag=$(git config --bool hooks.allowdeletetag) +allowmodifytag=$(git config --bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero="0000000000000000000000000000000000000000" +if [ "$newrev" = "$zero" ]; then + newrev_type=delete +else + newrev_type=$(git cat-file -t $newrev) +fi + +case "$refname","$newrev_type" in + refs/tags/*,commit) + # un-annotated tag + short_refname=${refname##refs/tags/} + if [ "$allowunannotated" != "true" ]; then + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 diff --git a/spec/fixtures/test.git/git/index b/spec/fixtures/test.git/git/index index 0b50aa9dba5e1558b06b0be6111dfb76abf9adc6..7117c7cf68fe6fc8a6921eaf8d391a01f1c81a6f 100644 GIT binary patch literal 217 zcmZ?q402{*U|<5_n2jH#827wg2BR4m{xLID&9-DrpT3=K4!Z!CU44ef;`FSPzdKtwGAwjOLK;tACj1&yGzCB9!$jP3| nAFyn~i7EHvX2=;H+|ac=M88C#Q|3qKNd}2%$Az!Ayl4RckseXp literal 209 zcmZ?q402{*U|<5_aE@p0K$-zYGcqu+Fy4A6%)rpNgn@zaD^N-Vh@Ew%XQutzI5#b7 zUi7x5d!Gm>SY>=?;K)eL$;sEtDhBH3TD2Bz4wMF)b7zY(QRZ-#=NILq=%p5$F@yxU zx&qCSWH3@N;40sGJeR>*VtbF{jy$stpC|Jj4nD_!>a~ DNX 1433058807 +0300 commit (initial): Initial commit -f37efccc1cef20309de28bfbdd16d0c4afb9d550 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas MozÅ«ras 1433058814 +0300 checkout: moving from master to semicolon -f37efccc1cef20309de28bfbdd16d0c4afb9d550 f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 Mindaugas MozÅ«ras 1433058820 +0300 commit: Remove semicolon -f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas MozÅ«ras 1456673968 +0200 checkout: moving from semicolon to master -f37efccc1cef20309de28bfbdd16d0c4afb9d550 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas MozÅ«ras 1456673985 +0200 commit (amend): Initial commit -85e04b1eb1a721d42db51d49e49dfeb8255a5741 f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 Mindaugas MozÅ«ras 1456673990 +0200 checkout: moving from master to semicolon -f7eb73cae47464f2d235a1d014c4617ad2aa0cb0 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas MozÅ«ras 1456673992 +0200 rebase: checkout master -85e04b1eb1a721d42db51d49e49dfeb8255a5741 e438134aac40ce86789d552f1bdada6582a987f6 Mindaugas MozÅ«ras 1456673992 +0200 rebase: Remove semicolon -e438134aac40ce86789d552f1bdada6582a987f6 e438134aac40ce86789d552f1bdada6582a987f6 Mindaugas MozÅ«ras 1456673992 +0200 rebase finished: returning to refs/heads/semicolon -e438134aac40ce86789d552f1bdada6582a987f6 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas MozÅ«ras 1456674159 +0200 checkout: moving from semicolon to master -85e04b1eb1a721d42db51d49e49dfeb8255a5741 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas MozÅ«ras 1456674164 +0200 commit (amend): Initial commit -931004157205727e6a47586feaed0473c6ddbd66 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas MozÅ«ras 1456674177 +0200 checkout: moving from master to curly -931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas MozÅ«ras 1456674189 +0200 commit: Add a line of code that does not have the correct curlies (eslint) -3a6237c5feacca9a37c36bec5110a1eeb9da703b 37018e429ad00f0ec961bd218e3dfa6a6e8cc05b Markus Doits 1460316876 +0200 commit: add es6 file +0000000000000000000000000000000000000000 08cc1f13f1d655a7353040edb359c7f3ab7f8bd4 Paul Bonaud 1555165913 +0200 commit (initial): Initial commit +08cc1f13f1d655a7353040edb359c7f3ab7f8bd4 08cc1f13f1d655a7353040edb359c7f3ab7f8bd4 Paul Bonaud 1555165937 +0200 checkout: moving from master to hlint +08cc1f13f1d655a7353040edb359c7f3ab7f8bd4 553b8ba14bc0100f71f0bbe45c7ad29a088f7c15 Paul Bonaud 1555165977 +0200 commit: Add hs files with hlint errors diff --git a/spec/fixtures/test.git/git/logs/refs/heads/curly b/spec/fixtures/test.git/git/logs/refs/heads/curly deleted file mode 100644 index 11582e5..0000000 --- a/spec/fixtures/test.git/git/logs/refs/heads/curly +++ /dev/null @@ -1,3 +0,0 @@ -0000000000000000000000000000000000000000 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas MozÅ«ras 1456674177 +0200 branch: Created from HEAD -931004157205727e6a47586feaed0473c6ddbd66 3a6237c5feacca9a37c36bec5110a1eeb9da703b Mindaugas MozÅ«ras 1456674189 +0200 commit: Add a line of code that does not have the correct curlies (eslint) -3a6237c5feacca9a37c36bec5110a1eeb9da703b 37018e429ad00f0ec961bd218e3dfa6a6e8cc05b Markus Doits 1460316876 +0200 commit: add es6 file diff --git a/spec/fixtures/test.git/git/logs/refs/heads/hlint b/spec/fixtures/test.git/git/logs/refs/heads/hlint new file mode 100644 index 0000000..8ed043d --- /dev/null +++ b/spec/fixtures/test.git/git/logs/refs/heads/hlint @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 08cc1f13f1d655a7353040edb359c7f3ab7f8bd4 Paul Bonaud 1555165928 +0200 branch: Created from master +08cc1f13f1d655a7353040edb359c7f3ab7f8bd4 553b8ba14bc0100f71f0bbe45c7ad29a088f7c15 Paul Bonaud 1555165977 +0200 commit: Add hs files with hlint errors diff --git a/spec/fixtures/test.git/git/logs/refs/heads/master b/spec/fixtures/test.git/git/logs/refs/heads/master index 752c737..4bcbe1d 100644 --- a/spec/fixtures/test.git/git/logs/refs/heads/master +++ b/spec/fixtures/test.git/git/logs/refs/heads/master @@ -1,3 +1 @@ -0000000000000000000000000000000000000000 f37efccc1cef20309de28bfbdd16d0c4afb9d550 Mindaugas MozÅ«ras 1433058807 +0300 commit (initial): Initial commit -f37efccc1cef20309de28bfbdd16d0c4afb9d550 85e04b1eb1a721d42db51d49e49dfeb8255a5741 Mindaugas MozÅ«ras 1456673985 +0200 commit (amend): Initial commit -85e04b1eb1a721d42db51d49e49dfeb8255a5741 931004157205727e6a47586feaed0473c6ddbd66 Mindaugas MozÅ«ras 1456674164 +0200 commit (amend): Initial commit +0000000000000000000000000000000000000000 08cc1f13f1d655a7353040edb359c7f3ab7f8bd4 Paul Bonaud 1555165913 +0200 commit (initial): Initial commit diff --git a/spec/fixtures/test.git/git/objects/01/d6dc2234bda69a289104ffdf9667363a2414bd b/spec/fixtures/test.git/git/objects/01/d6dc2234bda69a289104ffdf9667363a2414bd deleted file mode 100644 index b4fe9ea..0000000 --- a/spec/fixtures/test.git/git/objects/01/d6dc2234bda69a289104ffdf9667363a2414bd +++ /dev/null @@ -1,2 +0,0 @@ -x¥ŽA -Â0E]ç³d’ؘ‚ˆ ·b2™`°µÒLÑã[½‚»ÿ>ŸÇçi«‚ v£³p‘˜Øvè\‰iŸ= Å>±CJÉúÒÇ®ˆ$4Ošå¡à)8àµ$fêiÍ>$áÎZ$».ûLôÉТ·i†+Í÷¥ÁeªÚà8þh—¿tn*ð:+ßEwYN`÷½ ] °E‡hø÷Vå_¡œ¡ÔAàUõÒ´¥”ú61CW \ No newline at end of file diff --git a/spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92d b/spec/fixtures/test.git/git/objects/06/745b4cc11f505bdd1ecc84a744c3802729f92d deleted file mode 100644 index d0554e96026bda7ff3ffc69bd06079053c1fd054..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53 zcmV-50LuS(0V^p=O;s>9V=y!@Ff%bx$Vkn}$=Ay&X3&+Mnf7nv+_b29(c6~peIlS> LmGK<_KI9O&VAL6p diff --git a/spec/fixtures/test.git/git/objects/08/cc1f13f1d655a7353040edb359c7f3ab7f8bd4 b/spec/fixtures/test.git/git/objects/08/cc1f13f1d655a7353040edb359c7f3ab7f8bd4 new file mode 100644 index 0000000000000000000000000000000000000000..597935da3a4cfb9b853855b4b4cfc9e3cdc92866 GIT binary patch literal 132 zcmV-~0DJ#<0iBIa3W6aN09$*Cw+}wlR1_kjUAwN}&yyrS4SC)_sT;JMSONKg literal 0 HcmV?d00001 diff --git a/spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924 b/spec/fixtures/test.git/git/objects/22/2c064befc5a4f3192526863ce449c81bb74924 deleted file mode 100644 index 6fcbf2f7db2d52af7c9df9cba2fba724b1e44cad..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 86 zcmV-c0IC0Y0V^p=O;s>AW-v4`Ff%bx&`T}O$;>M$N@lpwu;q)xixt%`*~;&?MhVX{ s+pBvRswg8hCnsMotC+#+{fgPYIhJJB9&vnkvw-!rfpf|Y0O0K*RWlGL`2YX_ diff --git a/spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 b/spec/fixtures/test.git/git/objects/2d/1b9966feb19d665a9e5bb6a5bde410203a68f7 deleted file mode 100644 index f5fbdc534df59a48a106d6141541e9cee9d560bf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 73 zcmV-P0Ji^l0ZYosPf{>5XGkl}OD@UG&r|S7&B@6R&o9bJ(a1~8P1WS8=28HH%rpg! fwETQc1t6iVZ4DMn%tjXt)21F z>aHjOUG!sE1ckMW0|n-pLr{3OwN$vKo${;J))y~=> OC`YfgC-nm?y=Qk@Cue>D diff --git a/spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8 b/spec/fixtures/test.git/git/objects/3a/efa89bfb08a4697dc441eed97005eb304364d8 deleted file mode 100644 index c8a6c16275df9bc71f35509f94473b6cb4621375..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 57 zcmV-90LK4#0ZYosPf{>3XGkl}OD@UG&r|S7&B@6R&o9bJ(a1~8P1WS8=28HH#GKTk P5{QU3S1lI+0dWz8CUqLo diff --git a/spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6 b/spec/fixtures/test.git/git/objects/45/2143142df8628483f4a2fd4a4bbff9e89ea7a6 deleted file mode 100644 index 8a65f33c983c9c005043fcd445004bb32fdaca4e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 55 zcmV-70LcG%0ZYosPf{>3V@NB_OD@UG&r|S7&B@6R&o9bJ(a1~8P1WS8=28HH#GKTk N5~xTm7Xa^$5lHeF8t?!B diff --git a/spec/fixtures/test.git/git/objects/55/3b8ba14bc0100f71f0bbe45c7ad29a088f7c15 b/spec/fixtures/test.git/git/objects/55/3b8ba14bc0100f71f0bbe45c7ad29a088f7c15 new file mode 100644 index 0000000..e5eac74 --- /dev/null +++ b/spec/fixtures/test.git/git/objects/55/3b8ba14bc0100f71f0bbe45c7ad29a088f7c15 @@ -0,0 +1 @@ +xŽKŠÃ0g­Sô>Z–[Ã$'ÈôéÆfl+È2sý19B–õõ*×u; D_½1ƒX¬½Í6…‚BmÀìÃX„8xÍFgP½bã­úœµh#ºX¢è ‘K2²“ŸÊ¨âѧÚàu‹GÛë„kzÏ4î˼ý^s]¿A‘¶œƒ ˆê\ÏÎΟÔ½˜vyáþæ>ÁtvàÖjÛÕ?îØR4 \ No newline at end of file diff --git a/spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8 b/spec/fixtures/test.git/git/objects/76/0a0807c483b0f2b949acc9cc2ba8e37d4a7ff8 deleted file mode 100644 index 517545096b004e6b338b2bd5911274c9d1071955..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53 zcmV-50LuS(0V^p=O;s>9V=y!@Ff%bx$Vkn}$=Ay&W^h$>7Sa8Y)YANA(O)m`{XbvK LTfPhcI5H8YJ@pq& diff --git a/spec/fixtures/test.git/git/objects/77/b5c76d003b18b78c41b86e36884ce49f40c259 b/spec/fixtures/test.git/git/objects/77/b5c76d003b18b78c41b86e36884ce49f40c259 deleted file mode 100644 index db2600a917a42f8a95a95da550e350c26dd61340..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 66 zcmV-I0KNZs0V^p=O;s>AW-v4`Ff%bx$Vkn}$=Ay&X3&+Mnf7nv+_b29(c6~peIlS> YmGK>_raZqWCq*x{*bJ*80GBWye%K)%fB*mh diff --git a/spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741 b/spec/fixtures/test.git/git/objects/85/e04b1eb1a721d42db51d49e49dfeb8255a5741 deleted file mode 100644 index 153bd31eff7fae260b2279d49c2b5cd862dd8922..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 154 zcmV;L0A>Gp0iDi43d0}}h2gF}#q0|~$I&Q+(rp(xgs~9unx(L)P#Z0MAhOAW-v4`Ff%bx&`T}O$;>M$N@lpwu;q)xixt%`*~;&?MhVX{ s+pBvRswg8hCnsMotC+!6(OE?IM^a1kmqmZQy!ZcnF>m=Y0LykEe;KPL{Qv*} diff --git a/spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66 b/spec/fixtures/test.git/git/objects/93/1004157205727e6a47586feaed0473c6ddbd66 deleted file mode 100644 index f017b1abca864b94489a33c0f741a42b6699a2b2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 154 zcmV;L0A>Gp0iDiE3c@fHg<;28Mdm`ec{TwNrw+P^n@4M)X&|PPZpn4HF9YHRoE`qb z$MGfS)F@}{)M|{>&Yq(S0gP1)z$r6o=Y`Y(gLZCq!bU5&B)GRnsdP$Pz9V=y!@Ff%bx$Vkn}$=Ay&X0Up{V)k#2C7HEH9N*n6V0~@i LoN@yIO{o!lE{_&h diff --git a/spec/fixtures/test.git/git/objects/c8/0c26814ee76057a8493b791e6e1a623f693e97 b/spec/fixtures/test.git/git/objects/c8/0c26814ee76057a8493b791e6e1a623f693e97 new file mode 100644 index 0000000000000000000000000000000000000000..fb02b579aa6ea27b1953f12ca4c19ddf13ace113 GIT binary patch literal 58 zcmV-A0LA}!0ZYosPf{>3Vo+ApFD)+8Ps+^GPt7Y+NJ=cu;NnV6&d66#%E-ygD^W;J Q%*jbjQB>jr0Efa4cMEqK!TAW-v4`Ff%bx$Vkn}$=6FQHe=A0o|*P<PCm(A1vl>GH diff --git a/spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3 b/spec/fixtures/test.git/git/objects/d0/80b4f440e8a87be90677df855a139a36bd2dc3 deleted file mode 100644 index 9d54c76c6171d65662bee597e2350c3535a30a57..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 46 zcmV+}0MY+=0ZYosPf{>3W~k;;00O0=(wx*{B`XC87c5kqnwtp}F#;>7<*MZZ06*gk EkfyZ}r~m)} diff --git a/spec/fixtures/test.git/git/objects/dd/e5c6b931572a74d0824ad8268e826ba18647b4 b/spec/fixtures/test.git/git/objects/dd/e5c6b931572a74d0824ad8268e826ba18647b4 new file mode 100644 index 0000000000000000000000000000000000000000..0bff00bbcfca060e9810259b213f1f6bc8274016 GIT binary patch literal 146 zcmV;D0B!$x0ZYosPf{>6vtX#!RaWqE^m7k&baz$oFH0@T$xlp4O$jb3%FIhIR#4Wh z<>JcCPbtkwRR}1`&nwC2Qc%zUVg-fb#7d9UoE(sVrb2l}YEdc|S7vTOeo+ZX77APv zOA_@$QY%UnG(e;#7Z*&Mf|Zp5SVGrM0b(0MssyCLR-rf}zg$5@0mS1109DpCltGz0 A#{d8T literal 0 HcmV?d00001 diff --git a/spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6 b/spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6 deleted file mode 100644 index 37b8c14..0000000 --- a/spec/fixtures/test.git/git/objects/e4/38134aac40ce86789d552f1bdada6582a987f6 +++ /dev/null @@ -1 +0,0 @@ -xŽÍi1FsVºŒ4šÑjÀ7àK:ÐÏØY°VfWëƒ[Jé+º¤Ü>¼Ç—[­s×àíG_E4ƒ#áBC¶xF¾I€[fç)š„^=ã*KׁÄ`²’lœÀ„’††,Èeˆˆ"MhUÜûW[õu^JÜïqÓ×öþù^Ç8Õ?v¬í½t¹×8?Ž¹Õ³¶èœ¡ÀèƒqƨAÇã.ÿj‘÷“c†Ñ‚ÑRŸRÛKô&uÎíÑõ ß)VŸ \ No newline at end of file diff --git a/spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d550 b/spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d550 deleted file mode 100644 index 1b07d10..0000000 --- a/spec/fixtures/test.git/git/objects/f3/7efccc1cef20309de28bfbdd16d0c4afb9d550 +++ /dev/null @@ -1,3 +0,0 @@ -x­ÎK -Â0…aÇYŝ å&iÒDœ:è"n­¦šNº%×á¾ ˆ;pvø?ǗœSÁù©n1‚¼ «8¢SfÐÎË^ -Ú¹ÉI­=£½>ÊcZí3=a,ÇûµµqÉ?ër9öF·9SZ:_òx/%*cp€3JDÖ´=¨ñ-v_SM´À7Ê>»CHò \ No newline at end of file diff --git a/spec/fixtures/test.git/git/objects/f6/e267486c6b9d0f50a690c894df5e981e31c1b0 b/spec/fixtures/test.git/git/objects/f6/e267486c6b9d0f50a690c894df5e981e31c1b0 new file mode 100644 index 0000000000000000000000000000000000000000..8d9a1778bd0097fc53a8c69c1caeae3538144169 GIT binary patch literal 96 zcmV-m0H6PO0V^p=O;xZkU@$Z=FgG<-NG>fd$||eecnqOhy1fHmu+oyx@Mg29hH2Pz0n#5 h=M>0&>w{?89#{THOI$dY7t1H-iORjq;tQT5Si)MfR1g3F diff --git a/spec/fixtures/test.git/git/refs/heads/curly b/spec/fixtures/test.git/git/refs/heads/curly deleted file mode 100644 index 21919cd..0000000 --- a/spec/fixtures/test.git/git/refs/heads/curly +++ /dev/null @@ -1 +0,0 @@ -37018e429ad00f0ec961bd218e3dfa6a6e8cc05b diff --git a/spec/fixtures/test.git/git/refs/heads/hlint b/spec/fixtures/test.git/git/refs/heads/hlint new file mode 100644 index 0000000..a27bfd1 --- /dev/null +++ b/spec/fixtures/test.git/git/refs/heads/hlint @@ -0,0 +1 @@ +553b8ba14bc0100f71f0bbe45c7ad29a088f7c15 diff --git a/spec/fixtures/test.git/git/refs/heads/master b/spec/fixtures/test.git/git/refs/heads/master index 0cccce0..5a8fedf 100644 --- a/spec/fixtures/test.git/git/refs/heads/master +++ b/spec/fixtures/test.git/git/refs/heads/master @@ -1 +1 @@ -931004157205727e6a47586feaed0473c6ddbd66 +08cc1f13f1d655a7353040edb359c7f3ab7f8bd4 diff --git a/spec/fixtures/test.git/hello.js b/spec/fixtures/test.git/hello.js deleted file mode 100644 index 6ad633d..0000000 --- a/spec/fixtures/test.git/hello.js +++ /dev/null @@ -1,7 +0,0 @@ -function HelloWorld(name) -{ - if (foo) foo++; - alert(name); -} - -function Empty() {} diff --git a/spec/fixtures/test.git/pronto.hs b/spec/fixtures/test.git/pronto.hs new file mode 100644 index 0000000..dde5c6b --- /dev/null +++ b/spec/fixtures/test.git/pronto.hs @@ -0,0 +1,11 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Pronto + ( + sayHello + ) where + +import Data.Text (Text) + +sayHello :: Text -> String +sayHello text = show $ text diff --git a/spec/fixtures/test.git/world.es6 b/spec/fixtures/test.git/world.es6 deleted file mode 100644 index 2d1b996..0000000 --- a/spec/fixtures/test.git/world.es6 +++ /dev/null @@ -1,5 +0,0 @@ -function HelloWorld(name) -{ - if (foo) foo++; - alert(name); -} diff --git a/spec/pronto/eslint_spec.rb b/spec/pronto/eslint_spec.rb deleted file mode 100644 index 0924f30..0000000 --- a/spec/pronto/eslint_spec.rb +++ /dev/null @@ -1,163 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -module Pronto - describe ESLintNpm do - let(:eslint) { ESLintNpm.new(patches) } - let(:patches) { [] } - - describe '#run' do - subject(:run) { eslint.run } - - context 'patches are nil' do - let(:patches) { nil } - - it 'returns an empty array' do - expect(run).to eql([]) - end - end - - context 'no patches' do - let(:patches) { [] } - - it 'returns an empty array' do - expect(run).to eql([]) - end - end - - context 'patches with a one and a four warnings' do - include_context 'test repo' - - let(:patches) { repo.diff('master') } - - it 'returns correct number of errors' do - expect(run.count).to eql(5) - end - - it 'has correct first message' do - expect(run.first.msg).to eql("'foo' is not defined.") - end - - context( - 'with files to lint config that never matches', - config: { 'files_to_lint' => 'will never match' } - ) do - it 'returns zero errors' do - expect(run.count).to eql(0) - end - end - - context( - 'with files to lint config that matches only .js', - config: { 'files_to_lint' => '\.js$' } - ) do - it 'returns correct amount of errors' do - expect(run.count).to eql(2) - end - end - - context( - 'with cmd_line_opts to include .html', - config: { 'cmd_line_opts' => '--ext .html' } - ) do - it 'returns correct number of errors' do - expect(run.count).to eql 5 - end - end - - context( - 'with different eslint executable', - config: { 'eslint_executable' => './custom_eslint.sh' } - ) do - it 'calls the custom eslint eslint_executable' do - expect { run }.to raise_error(JSON::ParserError, /custom eslint called/) - end - end - end - - context 'repo with ignored and not ignored file, each with three warnings' do - include_context 'eslintignore repo' - - let(:patches) { repo.diff('master') } - - it 'returns correct number of errors' do - expect(run.count).to eql(3) - end - - it 'has correct first message' do - expect(run.first.msg).to eql("'HelloWorld' is defined but never used.") - end - end - end - - describe '#files_to_lint' do - subject(:files_to_lint) { eslint.files_to_lint } - - it 'matches .js by default' do - expect(files_to_lint).to match('my_js.js') - end - - it 'matches .es6 by default' do - expect(files_to_lint).to match('my_js.es6') - end - end - - describe '#eslint_executable' do - subject(:eslint_executable) { eslint.eslint_executable } - - it 'is `eslint` by default' do - expect(eslint_executable).to eql('eslint') - end - - context( - 'with different eslint executable config', - config: { 'eslint_executable' => 'custom_eslint' } - ) do - it 'is correct' do - eslint.read_config - expect(eslint_executable).to eql('custom_eslint') - end - end - end - - describe '#eslint_command_line' do - subject(:eslint_command_line) { eslint.send(:eslint_command_line, path) } - let(:path) { '/some/path.rb' } - - it 'adds json output flag' do - expect(eslint_command_line).to include('-f json') - end - - it 'adds path' do - expect(eslint_command_line).to include(path) - end - - it 'starts with eslint executable' do - expect(eslint_command_line).to start_with(eslint.eslint_executable) - end - - context 'with path that should be escaped' do - let(:path) { '/must be/$escaped' } - - it 'escapes the path correctly' do - expect(eslint_command_line).to include('/must\\ be/\\$escaped') - end - - it 'does not include unescaped path' do - expect(eslint_command_line).not_to include(path) - end - end - - context( - 'with some command line options', - config: { 'cmd_line_opts' => '--my command --line opts' } - ) do - it 'includes the custom command line options' do - eslint.read_config - expect(eslint_command_line).to include('--my command --line opts') - end - end - end - end -end diff --git a/spec/pronto/hlint_spec.rb b/spec/pronto/hlint_spec.rb new file mode 100644 index 0000000..fdabab5 --- /dev/null +++ b/spec/pronto/hlint_spec.rb @@ -0,0 +1,138 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Pronto + module Hlint + describe Runner do + let(:hlint) { Hlint::Runner.new(patches) } + let(:patches) { [] } + + describe '#run' do + subject(:run) { hlint.run } + + context 'patches are nil' do + let(:patches) { nil } + + it 'returns an empty array' do + expect(run).to eql([]) + end + end + + context 'no patches' do + let(:patches) { [] } + + it 'returns an empty array' do + expect(run).to eql([]) + end + end + + context 'patches with a one and a four warnings' do + include_context 'test repo' + + let(:patches) { repo.diff('master') } + + it 'returns correct number of errors' do + expect(run.count).to eql(3) + end + + it 'has correct first message' do + expect(run.first.msg).to match("Unused LANGUAGE pragma") + end + + context( + 'with files to lint config that never matches', + config: { 'files_to_lint' => 'will never match' } + ) do + it 'returns zero errors' do + expect(run.count).to eql(0) + end + end + + context( + 'with files to lint config that matches only .lhs', + config: { 'files_to_lint' => '\.lhs$' } + ) do + it 'returns correct amount of errors' do + expect(run.count).to eql(0) + end + end + + context( + 'with different hlint executable', + config: { 'hlint_executable' => './custom_hlint.sh' } + ) do + it 'calls the custom hlint hlint_executable' do + expect { run }.to raise_error(JSON::ParserError, /hlint called!/) + end + end + end + end + + describe '#files_to_lint' do + subject(:files_to_lint) { hlint.files_to_lint } + + it 'matches .he by default' do + expect(files_to_lint).to match('Types.hs') + end + end + + describe '#hlint_executable' do + subject(:hlint_executable) { hlint.hlint_executable } + + it 'is `hlint` by default' do + expect(hlint_executable).to eql('hlint') + end + + context( + 'with different hlint executable config', + config: { 'hlint_executable' => 'custom_hlint' } + ) do + it 'is correct' do + hlint.read_config + expect(hlint_executable).to eql('custom_hlint') + end + end + end + + describe '#hlint_command_line' do + subject(:hlint_command_line) { hlint.send(:hlint_command_line, path) } + let(:path) { '/some/path.rb' } + + it 'adds json output flag' do + expect(hlint_command_line).to include('--json') + end + + it 'adds path' do + expect(hlint_command_line).to include(path) + end + + it 'starts with hlint executable' do + expect(hlint_command_line).to start_with(hlint.hlint_executable) + end + + context 'with path that should be escaped' do + let(:path) { '/must be/$escaped' } + + it 'escapes the path correctly' do + expect(hlint_command_line).to include('/must\\ be/\\$escaped') + end + + it 'does not include unescaped path' do + expect(hlint_command_line).not_to include(path) + end + end + + context( + 'with some command line options', + config: { 'cmd_line_opts' => '--my command --line opts' } + ) do + it 'includes the custom command line options' do + hlint.read_config + expect(hlint_command_line).to include('--my command --line opts') + end + end + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e147ea7..656e116 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,10 @@ # frozen_string_literal: true require 'fileutils' -require 'byebug' require 'rspec' -require 'pronto/eslint_npm' +require 'pronto/hlint' -%w[test eslintignore].each do |repo_name| +%w[test].each do |repo_name| RSpec.shared_context "#{repo_name} repo" do let(:git) { "spec/fixtures/#{repo_name}.git/git" } let(:dot_git) { "spec/fixtures/#{repo_name}.git/.git" } @@ -20,9 +19,9 @@ RSpec.shared_context 'with config', config: true do requested_config = metadata[:config] before(:each) do - allow_any_instance_of(Pronto::ESLintNpm).to receive(:config_options).and_return(requested_config) + allow_any_instance_of(Pronto::Hlint::Runner).to receive(:config_options).and_return(requested_config) # make sure the config is actually read in the example - expect_any_instance_of(Pronto::ESLintNpm).to receive(:read_config).and_call_original + expect_any_instance_of(Pronto::Hlint::Runner).to receive(:read_config).and_call_original end end -- 2.41.0