strict-todo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 734ac657716c363d1d1625a0427d5b7721516304d282ec012e5b799e0924591e
4
+ data.tar.gz: 5c1f5f89c2e79123259b10a72f11c7afe3b39a50e2e59e98e732865156d5487a
5
+ SHA512:
6
+ metadata.gz: b6185c032adf9e21f0fb905bc41bfee5aeefebf8c3a55788a343895f8fe75d28918ad288ec280a2f381ad015babd6f9d1d54dcf038600a29ec3f36b9464073bc
7
+ data.tar.gz: 4bbcc03ecbaeb479db8edbf92b561487e4114e443474401d636998c4bc808a751968ea253127cd4426ed1f5e1b8cd4273e0f86bc5ddd616459308d6088c9aed3
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.7
17
+ bundle install
18
+ bundle exec rake
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 3.0.0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in strict_todo.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 tunagohan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Strict::Todo
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/strict/todo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'strict-todo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install strict-todo
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/strict-todo.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: %i[spec]
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require_relative "../lib/strict_todo"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ common:
2
+ exclude:
3
+ - 'node_modules'
4
+ - 'tmp'
5
+ - 'vendor'
6
+ - '.git'
7
+ - 'Gemfile.lock'
8
+ - 'lib'
9
+ - 'db'
10
+ extension:
11
+ - '.rb'
12
+ - '.erb'
13
+ - '.vue'
14
+ - '.css'
15
+ - '.scss'
16
+ - ''
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # TODO: やることリストを洗い出す
4
+
5
+ require_relative "../lib/strict_todo/executable"
6
+
7
+ StrictTodo::Executable.perform
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StrictTodo
4
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module StrictTodo
6
+ class Checker
7
+ class << self
8
+ def perform(line:)
9
+ delete_index = line.index('TODO') || line.index('FIXME')
10
+ return nil if delete_index.nil?
11
+
12
+ parse_line = line.slice(delete_index..)
13
+
14
+ unless delete_index.zero?
15
+ line.slice!(0..delete_index-1)
16
+ end
17
+
18
+ if check_format(line: parse_line).nil?
19
+ return "フォーマットエラー"
20
+ end
21
+
22
+ date = parse_line.match(/[0-9]{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])/)[0]
23
+ if check_date(date: date)
24
+ return "期限を過ぎています"
25
+ end
26
+
27
+ nil
28
+ end
29
+
30
+ private
31
+
32
+ def check_format(line:)
33
+ line =~ /\A(TODO|FIXME)\((\w|-)*:[0-9]{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\).*\Z/
34
+ end
35
+
36
+ def check_date(date:)
37
+ Date.parse(date) < Date.today
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module StrictTodo
6
+ class Config
7
+ private_class_method :new
8
+
9
+ COMMON = YAML.safe_load(File.read("config/config.yml")).fetch("common").freeze
10
+
11
+ # @return [Array] 除外対象
12
+ attr_reader :exclude_match
13
+ # @return [Array] 検索対象の拡張子
14
+ attr_reader :permit_extensions
15
+
16
+ def initialize
17
+ @exclude_match = COMMON.fetch("exclude")
18
+ @permit_extensions = COMMON.fetch("extension")
19
+ end
20
+
21
+ class << self
22
+ def load
23
+ return new.freeze()
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'config'
4
+ require_relative 'find_file'
5
+ require_relative 'find_word'
6
+ require_relative 'checker'
7
+
8
+
9
+
10
+ module StrictTodo
11
+ class Executable
12
+ private_class_method :new
13
+
14
+ class << self
15
+ def perform
16
+ results = {}
17
+
18
+ config = StrictTodo::Config.load
19
+ files = StrictTodo::FindFile.perform(config: config, base_dir: '.')
20
+
21
+ files.each do |file|
22
+ results.update(StrictTodo::FindWord.perform(file_path: file))
23
+ end
24
+
25
+ results.each_key do |key|
26
+ error = StrictTodo::Checker.perform(line: results[key][:description])
27
+ results[key][:error] = error
28
+ end
29
+
30
+ output(objects: results)
31
+ end
32
+
33
+ private
34
+
35
+ def output(objects:)
36
+ objects.each_key do |key|
37
+ if objects[key][:error].nil?
38
+ puts "#{objects[key][:header]} \e[1m\e[32mSuccess\e[0m\n=> #{objects[key][:description]}\n\e[0m"
39
+ else
40
+ puts "#{objects[key][:header]} \e[1m\e[31m#{objects[key][:error]}\e[0m\n=> #{objects[key][:description]}\n\e[0m"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StrictTodo
4
+ class FindFile
5
+ private_class_method :new
6
+
7
+ class << self
8
+ #
9
+ # @param [StrictTodo::Config] config YamlロードされHash化されたConfig情報
10
+ # @param [String] base_dir 起点となるディレクトリ
11
+ #
12
+ # @return [Array<String>] ファイルのパス情報
13
+ #
14
+ def perform(config:, base_dir:)
15
+ results = []
16
+ Dir.glob('**/*', File::FNM_DOTMATCH, base: base_dir) do |path|
17
+ # ディレクトリならば更に再起探索を行う
18
+ if File.directory?(path)
19
+ next
20
+ end
21
+
22
+ if acceptable?(dir_path: path, config: config)
23
+ results.push(path)
24
+ end
25
+ end
26
+ results
27
+ end
28
+
29
+ private
30
+
31
+ #
32
+ # @param [String] dir_path ディレクトリパス
33
+ # @param [StrictTodo::Config] config YamlロードされHash化されたConfig情報
34
+ #
35
+ def acceptable?(dir_path:, config:)
36
+ return false if not config.permit_extensions.include?(File.extname(dir_path))
37
+ return false if config.exclude_match.include?(dir_path.split("/").first)
38
+
39
+ true
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StrictTodo
4
+ class FindWord
5
+ private_class_method :new
6
+
7
+ class << self
8
+ def perform(file_path:)
9
+ results = {}
10
+ File.readlines(file_path, chomp: true).each.with_index(1) do |line, index|
11
+ if line.include?('TODO')
12
+ results["#{file_path}:#{index.to_s}"] = {
13
+ header: extraction_todo(file_path: file_path, index: index),
14
+ description: line
15
+ }
16
+ end
17
+
18
+ if line.include?('FIXME')
19
+ results["#{file_path}:#{index.to_s}"] = {
20
+ header: extraction_fixme(file_path: file_path, index: index),
21
+ description: line
22
+ }
23
+ end
24
+ end
25
+ results
26
+ end
27
+
28
+ private
29
+
30
+ def extraction_todo(file_path:, index:)
31
+ "TODO(#{file_path}:#{index})"
32
+ end
33
+
34
+ def extraction_fixme(file_path:, index:)
35
+ "FIXME(#{file_path}:#{index})"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StrictTodo
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/strict_todo/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "strict-todo"
7
+ spec.version = StrictTodo::VERSION
8
+ spec.authors = ["tunagohan"]
9
+ spec.email = ["kazuxtuna@gmail.com"]
10
+
11
+ spec.summary = "Strict to do management."
12
+ spec.description = "Strict to do management. Have them describe who will do what by when. This is to avoid leaving meaningless to do."
13
+ spec.homepage = "https://github.com/tunagohan/strict-todo"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strict-todo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - tunagohan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Strict to do management. Have them describe who will do what by when.
14
+ This is to avoid leaving meaningless to do.
15
+ email:
16
+ - kazuxtuna@gmail.com
17
+ executables:
18
+ - todo
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".github/workflows/main.yml"
23
+ - ".gitignore"
24
+ - ".rspec"
25
+ - ".ruby-version"
26
+ - Gemfile
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - config/config.yml
33
+ - exe/todo
34
+ - lib/strict_todo.rb
35
+ - lib/strict_todo/checker.rb
36
+ - lib/strict_todo/config.rb
37
+ - lib/strict_todo/executable.rb
38
+ - lib/strict_todo/find_file.rb
39
+ - lib/strict_todo/find_word.rb
40
+ - lib/strict_todo/version.rb
41
+ - strict_todo.gemspec
42
+ homepage: https://github.com/tunagohan/strict-todo
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.4.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.2.3
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Strict to do management.
65
+ test_files: []