Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove codeclimate for linting #475

Merged
merged 10 commits into from Jul 25, 2018
89 changes: 72 additions & 17 deletions .circleci/config.yml
Expand Up @@ -11,8 +11,8 @@ steps: &steps
- dependencies-{{ checksum "Gemfile.lock" }}

- run:
name: Run CI checks
command: bin/ci.sh
name: Run tests
command: bin/test.sh

- run:
name: Save coverage
Expand All @@ -26,9 +26,29 @@ steps: &steps
- save_cache:
key: dependencies-{{ checksum "Gemfile.lock" }}
paths:
- .vendor/bundle
- .bundle

jobs:
lint:
docker:
- image: deividrodriguez/byebug:2.5.1-readline-clang

steps:
- checkout

- restore_cache:
keys:
- dependencies-{{ checksum "Gemfile.lock" }}

- run:
name: Run linters
command: bin/lint.sh

- save_cache:
key: dependencies-{{ checksum "Gemfile.lock" }}
paths:
- .bundle

prior-to-prior-to-latest-readline-gcc:
docker:
- image: deividrodriguez/byebug:2.3.7-readline-gcc
Expand Down Expand Up @@ -112,20 +132,55 @@ workflows:

test:
jobs:
- prior-to-prior-to-latest-readline-gcc
- prior-to-prior-to-latest-libedit-gcc
- prior-to-prior-to-latest-readline-clang
- prior-to-prior-to-latest-libedit-clang

- prior-to-latest-readline-gcc
- prior-to-latest-libedit-gcc
- prior-to-latest-readline-clang
- prior-to-latest-libedit-clang

- latest-readline-gcc
- latest-libedit-gcc
- latest-readline-clang
- latest-libedit-clang
- lint

- prior-to-prior-to-latest-readline-gcc:
requires:
- lint

- prior-to-prior-to-latest-libedit-gcc:
requires:
- lint

- prior-to-prior-to-latest-readline-clang:
requires:
- lint

- prior-to-prior-to-latest-libedit-clang:
requires:
- lint

- prior-to-latest-readline-gcc:
requires:
- lint

- prior-to-latest-libedit-gcc:
requires:
- lint

- prior-to-latest-readline-clang:
requires:
- lint

- prior-to-latest-libedit-clang:
requires:
- lint

- latest-readline-gcc:
requires:
- lint

- latest-libedit-gcc:
requires:
- lint

- latest-readline-clang:
requires:
- lint

- latest-libedit-clang:
requires:
- lint

- upload_coverage:
requires:
Expand Down
54 changes: 18 additions & 36 deletions .codeclimate.yml
Expand Up @@ -3,53 +3,35 @@
version: "2"

checks:
argument-count:
enabled: false

complex-logic:
enabled: false

file-lines:
config:
threshold: 370
enabled: false

method-complexity:
config:
threshold: 13
enabled: false

method-count:
config:
threshold: 25
enabled: false

method-lines:
enabled: false

nested-control-flow:
enabled: false

return-statements:
config:
threshold: 5
enabled: false

similar-code:
enabled: false

plugins:
grep:
enabled: true

config:
patterns:
no-trailing-whitespace:
pattern: \s*$
annotation: "Don't leave trailing whitespace"
severity: minor
categories: Style
path_patterns:
- .rubocop.yml
- .rubocop_todo.yml
- .travis.yml

no-tabs:
pattern: " "
annotation: "Don't use hard tabs"
severity: minor
categories: Style
path_patterns:
- .rubocop.yml
- .rubocop_todo.yml
- .travis.yml

shellcheck:
enabled: true
identical-code:
enabled: false

exclude_patterns:
- .bundle/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -35,7 +35,7 @@ install:
fi

script:
- bin/ci.sh
- bin/test.sh

matrix:
fast_finish: true
Expand Down
16 changes: 2 additions & 14 deletions CONTRIBUTING.md
Expand Up @@ -43,20 +43,8 @@ abide by its terms.

## Code style

* Byebug uses [codeclimate][] to enforce code style. You can run codeclimate
checks locally using the [codeclimate CLI][] with `codeclimate analyze`.

* It also uses some extra style checks that are not available in codeclimate.
You can run those using `bin/rake lint`. These tasks are:

* Linting of c-files using `clang-format`. Configuration is specific to
clang-format 3.8, you may need some extra work to get that installed on macOS,
see below.

* Checking correct executable bit on repository files.

[codeclimate]: https://codeclimate.com/github/deivid-rodriguez/byebug
[codeclimate CLI]: https://github.com/codeclimate/codeclimate
* Byebug uses several style checks to check code style consistent. You can run
those using `bin/rake lint`.

### Runnning `clang-format` on macOS

Expand Down
2 changes: 0 additions & 2 deletions README.md
Expand Up @@ -6,12 +6,10 @@
[![Gitter][irc]][irc_url]

[gem]: https://img.shields.io/gem/v/byebug.svg
[mai]: https://api.codeclimate.com/v1/badges/f1a1bec582752c22da80/maintainability
[cov]: https://api.codeclimate.com/v1/badges/f1a1bec582752c22da80/test_coverage
[irc]: https://img.shields.io/badge/IRC%20(gitter)-devs%20%26%20users-brightgreen.svg

[gem_url]: https://rubygems.org/gems/byebug
[mai_url]: https://codeclimate.com/github/deivid-rodriguez/byebug/maintainability
[cov_url]: https://codeclimate.com/github/deivid-rodriguez/byebug/test_coverage
[irc_url]: https://gitter.im/deivid-rodriguez/byebug

Expand Down
29 changes: 25 additions & 4 deletions Rakefile
Expand Up @@ -38,7 +38,7 @@ end

namespace :lint do
desc "Run all linters"
task all: %i[clang_format unnecessary_executables rubocop mdl]
task all: %i[clang_format executables tabs trailing_whitespace rubocop mdl]

require_relative "tasks/linter"

Expand All @@ -50,25 +50,46 @@ namespace :lint do
end

desc "Check unnecessary execute permissions"
task :unnecessary_executables do
task :executables do
puts "Checking for unnecessary executables"

ExecutableLinter.new.run
end

desc "Check for tabs"
task :tabs do
puts "Checking for unnecessary tabs"

TabLinter.new.run
end

desc "Check for trailing whitespace"
task :trailing_whitespace do
puts "Checking for unnecessary trailing whitespace"

TrailingWhitespaceLinter.new.run
end

require "rubocop/rake_task"

RuboCop::RakeTask.new

desc "Checks markdown code style with Markdownlint"
task :mdl do
puts "Running mdl..."
puts "Running mdl"

abort unless system("mdl", *Dir.glob("*.md"))
end

desc "Checks shell code style with shellcheck"
task :shellcheck do
puts "Running shellcheck"

abort unless system("shellcheck", *Dir.glob("bin/*.sh"))
end
end

desc "Runs lint tasks not available on codeclimate"
desc "Runs lint tasks"
task lint: "lint:all"

namespace :docker do
Expand Down
4 changes: 3 additions & 1 deletion bin/ci.sh → bin/lint.sh
@@ -1,8 +1,10 @@
#!/usr/bin/env bash

set -eo pipefail

set +x

bin/bundle install --jobs 3 --retry 3 --path .bundle
bin/rake
bin/rake lint

set -x
10 changes: 10 additions & 0 deletions bin/test.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -eo pipefail

set +x

bin/bundle install --jobs 3 --retry 3 --path .bundle
bin/rake compile test

set -x
32 changes: 32 additions & 0 deletions tasks/linter.rb
Expand Up @@ -76,3 +76,35 @@ def clean?(file)
(in_exec_folder && executable) || (!in_exec_folder && !executable)
end
end

#
# Checks no tabs in source code
#
class TabLinter
include LinterMixin

def applicable_files
Open3.capture2("git ls-files")[0].split
end

def clean?(file)
relative_path = Pathname.new(__FILE__).relative_path_from(Pathname.new(File.dirname(__dir__))).to_s

file == relative_path || !File.read(file, encoding: Encoding::UTF_8).include?(" ")
end
end

#
# Checks trailing whitespace
#
class TrailingWhitespaceLinter
include LinterMixin

def applicable_files
Open3.capture2("git ls-files")[0].split
end

def clean?(file)
!File.read(file, encoding: Encoding::UTF_8).match?(/ +$/)
end
end