-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit caca02b
Showing
24 changed files
with
1,365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Test | ||
on: [push] | ||
jobs: | ||
unit-test: | ||
runs-on: macOS-11 | ||
env: | ||
DEVELOPER_DIR: /Applications/Xcode_12.5.app/Contents/Developer | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: bin/download_periphery | ||
- run: bundle install | ||
- run: bundle exec rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
.idea/ | ||
.yardoc | ||
Gemfile.lock | ||
pkg | ||
bin/periphery | ||
bin/lib_InternalSwiftSyntaxParser.dylib | ||
xcuserdata | ||
project.xcworkspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--color | ||
--require spec_helper | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml | ||
|
||
# If you don't like these settings, just delete this file :) | ||
|
||
AllCops: | ||
TargetRubyVersion: 2.0 | ||
|
||
Style/StringLiterals: | ||
EnforcedStyle: double_quotes | ||
Enabled: true | ||
|
||
# kind_of? is a good way to check a type | ||
Style/ClassCheck: | ||
EnforcedStyle: kind_of? | ||
|
||
# It's better to be more explicit about the type | ||
Style/BracesAroundHashParameters: | ||
Enabled: false | ||
|
||
# specs sometimes have useless assignments, which is fine | ||
Lint/UselessAssignment: | ||
Exclude: | ||
- '**/spec/**/*' | ||
|
||
# We could potentially enable the 2 below: | ||
Layout/IndentHash: | ||
Enabled: false | ||
|
||
Layout/AlignHash: | ||
Enabled: false | ||
|
||
# HoundCI doesn't like this rule | ||
Layout/DotPosition: | ||
Enabled: false | ||
|
||
# We allow !! as it's an easy way to convert ot boolean | ||
Style/DoubleNegation: | ||
Enabled: false | ||
|
||
# Cop supports --auto-correct. | ||
Lint/UnusedBlockArgument: | ||
Enabled: false | ||
|
||
# We want to allow class Fastlane::Class | ||
Style/ClassAndModuleChildren: | ||
Enabled: false | ||
|
||
Metrics/AbcSize: | ||
Max: 60 | ||
|
||
# The %w might be confusing for new users | ||
Style/WordArray: | ||
MinSize: 19 | ||
|
||
# raise and fail are both okay | ||
Style/SignalException: | ||
Enabled: false | ||
|
||
# Better too much 'return' than one missing | ||
Style/RedundantReturn: | ||
Enabled: false | ||
|
||
# Having if in the same line might not always be good | ||
Style/IfUnlessModifier: | ||
Enabled: false | ||
|
||
# and and or is okay | ||
Style/AndOr: | ||
Enabled: false | ||
|
||
# Configuration parameters: CountComments. | ||
Metrics/ClassLength: | ||
Max: 350 | ||
|
||
Metrics/CyclomaticComplexity: | ||
Max: 17 | ||
|
||
# Configuration parameters: AllowURI, URISchemes. | ||
Metrics/LineLength: | ||
Max: 370 | ||
|
||
# Configuration parameters: CountKeywordArgs. | ||
Metrics/ParameterLists: | ||
Max: 10 | ||
|
||
Metrics/PerceivedComplexity: | ||
Max: 18 | ||
|
||
# Sometimes it's easier to read without guards | ||
Style/GuardClause: | ||
Enabled: false | ||
|
||
# something = if something_else | ||
# that's confusing | ||
Style/ConditionalAssignment: | ||
Enabled: false | ||
|
||
# Better to have too much self than missing a self | ||
Style/RedundantSelf: | ||
Enabled: false | ||
|
||
Metrics/MethodLength: | ||
Max: 60 | ||
|
||
# We're not there yet | ||
Style/Documentation: | ||
Enabled: false | ||
|
||
# Adds complexity | ||
Style/IfInsideElse: | ||
Enabled: false | ||
|
||
# danger specific | ||
|
||
Style/BlockComments: | ||
Enabled: false | ||
|
||
Layout/MultilineMethodCallIndentation: | ||
EnforcedStyle: indented | ||
|
||
# FIXME: 25 | ||
Metrics/BlockLength: | ||
Max: 345 | ||
Exclude: | ||
- "**/*_spec.rb" | ||
|
||
Style/MixinGrouping: | ||
Enabled: false | ||
|
||
Style/FileName: | ||
Enabled: false | ||
|
||
Layout/IndentHeredoc: | ||
Enabled: false | ||
|
||
Style/SpecialGlobalVars: | ||
Enabled: false | ||
|
||
PercentLiteralDelimiters: | ||
PreferredDelimiters: | ||
"%": () | ||
"%i": () | ||
"%q": () | ||
"%Q": () | ||
"%r": "{}" | ||
"%s": () | ||
"%w": () | ||
"%W": () | ||
"%x": () | ||
|
||
Security/YAMLLoad: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
language: ruby | ||
cache: | ||
directories: | ||
- bundle | ||
|
||
rvm: | ||
- 2.0 | ||
- 2.1.3 | ||
- 2.3.1 | ||
|
||
script: | ||
- bundle exec rake spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in danger-periphery.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# A guardfile for making Danger Plugins | ||
# For more info see https://github.com/guard/guard#readme | ||
|
||
# To run, use `bundle exec guard`. | ||
|
||
guard :rspec, cmd: 'bundle exec rspec' do | ||
require 'guard/rspec/dsl' | ||
dsl = Guard::RSpec::Dsl.new(self) | ||
|
||
# RSpec files | ||
rspec = dsl.rspec | ||
watch(rspec.spec_helper) { rspec.spec_dir } | ||
watch(rspec.spec_support) { rspec.spec_dir } | ||
watch(rspec.spec_files) | ||
|
||
# Ruby files | ||
ruby = dsl.ruby | ||
dsl.watch_spec_files_for(ruby.lib_files) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2021 Ryosuke Ito <rito.0305@gmail.com> | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# danger-periphery | ||
|
||
A description of danger-periphery. | ||
|
||
## Installation | ||
|
||
$ gem install danger-periphery | ||
|
||
## Usage | ||
|
||
Methods and attributes from this plugin are available in | ||
your `Dangerfile` under the `periphery` namespace. | ||
|
||
## Development | ||
|
||
1. Clone this repo | ||
2. Run `bundle install` to setup dependencies. | ||
3. Run `bundle exec rake spec` to run the tests. | ||
4. Use `bundle exec guard` to automatically have tests run as you make changes. | ||
5. Make your changes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
require 'rubocop/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:specs) | ||
|
||
task default: :specs | ||
|
||
task :spec do | ||
Rake::Task['specs'].invoke | ||
Rake::Task['rubocop'].invoke | ||
Rake::Task['spec_docs'].invoke | ||
end | ||
|
||
desc 'Run RuboCop on the lib/specs directory' | ||
RuboCop::RakeTask.new(:rubocop) do |task| | ||
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb'] | ||
end | ||
|
||
desc 'Ensure that the plugin passes `danger plugins lint`' | ||
task :spec_docs do | ||
sh 'bundle exec danger plugins lint' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
cd "$(dirname "$0")" | ||
version="2.8.1" | ||
curl -Lo periphery.zip "https://github.com/peripheryapp/periphery/releases/download/$version/periphery-v$version.zip" | ||
unzip periphery.zip | ||
rm periphery.zip LICENSE.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'periphery/gem_version.rb' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'danger-periphery' | ||
spec.version = Periphery::VERSION | ||
spec.authors = ['Ryosuke Ito'] | ||
spec.email = ['rito.0305@gmail.com'] | ||
spec.description = %q{A Danger plugin to detect unused codes.} | ||
spec.summary = spec.description | ||
spec.homepage = 'https://github.com/manicmaniac/danger-periphery' | ||
spec.license = 'MIT' | ||
|
||
spec.files = `git ls-files`.split($/) | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0' | ||
|
||
# General ruby development | ||
spec.add_development_dependency 'bundler', '~> 2.0' | ||
spec.add_development_dependency 'rake', '~> 10.0' | ||
|
||
# Testing support | ||
spec.add_development_dependency 'rspec', '~> 3.4' | ||
|
||
# Linting code and docs | ||
spec.add_development_dependency "rubocop" | ||
spec.add_development_dependency "yard" | ||
|
||
# Makes testing easy via `bundle exec guard` | ||
spec.add_development_dependency 'guard', '~> 2.14' | ||
spec.add_development_dependency 'guard-rspec', '~> 4.7' | ||
|
||
# If you want to work on older builds of ruby | ||
spec.add_development_dependency 'listen', '3.0.7' | ||
|
||
# This gives you the chance to run a REPL inside your tests | ||
# via: | ||
# | ||
# require 'pry' | ||
# binding.pry | ||
# | ||
# This will stop test execution and let you inspect the results | ||
spec.add_development_dependency 'pry' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "periphery/gem_version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require "periphery/runner" | ||
require "periphery/scan_log_parser" | ||
|
||
module Danger | ||
# This is your plugin class. Any attributes or methods you expose here will | ||
# be available from within your Dangerfile. | ||
# | ||
# To be published on the Danger plugins site, you will need to have | ||
# the public interface documented. Danger uses [YARD](http://yardoc.org/) | ||
# for generating documentation from your plugin source, and you can verify | ||
# by running `danger plugins lint` or `bundle exec rake spec`. | ||
# | ||
# You should replace these comments with a public description of your library. | ||
# | ||
# @example Ensure people are well warned about merging on Mondays | ||
# | ||
# my_plugin.warn_on_mondays | ||
# | ||
# @see Ryosuke Ito/danger-periphery | ||
# @tags monday, weekends, time, rattata | ||
# | ||
class DangerPeriphery < Plugin | ||
|
||
# An attribute that you can read/write from your Dangerfile | ||
# | ||
# @return String | ||
attr_accessor :binary_path | ||
|
||
# A method that you can call from your Dangerfile | ||
# @return [Array<String>] | ||
# | ||
def scan(**options) | ||
output = Periphery::Runner.new(binary_path).scan(options) | ||
entries = Periphery::ScanLogParser.new.parse(output) | ||
files = files_in_diff | ||
entries. | ||
select { |entry| files.include?(entry.path) }. | ||
each { |entry| warn(entry.message, file: entry.path, line: entry.line) } | ||
end | ||
|
||
private | ||
|
||
def files_in_diff | ||
# Taken from https://github.com/ashfurrow/danger-ruby-swiftlint/blob/5184909aab00f12954088684bbf2ce5627e08ed6/lib/danger_plugin.rb#L214-L216 | ||
renamed_files_hash = git.renamed_files.map { |rename| [rename[:before], rename[:after]] }.to_h | ||
post_rename_modified_files = git.modified_files.map { |modified_file| renamed_files_hash[modified_file] || modified_file } | ||
(post_rename_modified_files - git.deleted_files) + git.added_files | ||
end | ||
end | ||
end |
Oops, something went wrong.