codefuckery 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +23 -0
- data/LICENSE +22 -0
- data/README.md +69 -0
- data/Rakefile +8 -0
- data/bin/codefuckery +49 -0
- data/codefuckery.gemspec +24 -0
- data/lib/codefuckery.rb +3 -0
- data/lib/codefuckery/counter.rb +60 -0
- data/lib/codefuckery/default_words.rb +3 -0
- data/lib/codefuckery/version.rb +3 -0
- data/test/test_counter.rb +62 -0
- data/test/test_default_words.rb +8 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5677274dbecfb4478d1b6e3b9ac8c1c299445a51d72a78d48c7b85a2e26ef2b2
|
4
|
+
data.tar.gz: d76e7811d17c046cee4f6620dcf5af6e43c9a4bcf57c8555385d5d8d739436d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ce38557f659a1a51e295dc170d845a7035d402f9fad223e138f5d33e911d2dd93edc2a15e2c019335d0606a445d9b5a5b2de466ac0b298148de85f65fcf7c00
|
7
|
+
data.tar.gz: 5b78faaeb513b8292eb80741f135623116e4de5d122fc19517fe49d6761150c7fe81aae54733695dc60b0df40181b26fec862837e850069ce5c92f3fd5084ac5
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codefuckery (0.0.1)
|
5
|
+
clamp (~> 1.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
clamp (1.3.1)
|
11
|
+
minitest (5.13.0)
|
12
|
+
rake (13.0.0)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
codefuckery!
|
19
|
+
minitest
|
20
|
+
rake
|
21
|
+
|
22
|
+
BUNDLED WITH
|
23
|
+
2.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2019 Martin Höller
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Codefuckery
|
2
|
+
|
3
|
+
Find out how fucked up your code is.
|
4
|
+
|
5
|
+
[](https://travis-ci.com/martinhoeller/codefuckery)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'codefuckery'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install the gem:
|
22
|
+
|
23
|
+
```
|
24
|
+
gem install codefuckery
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
Run `codefuckery` from the command line. Provide the directory with your source code as a parameter.
|
29
|
+
By default it will count the words `fuck`, `shit` and `sorry` recursively in all files.
|
30
|
+
|
31
|
+
```
|
32
|
+
$ codefuckery path/to/your/source
|
33
|
+
```
|
34
|
+
|
35
|
+
Output:
|
36
|
+
```
|
37
|
+
fuck: 4
|
38
|
+
shit: 12
|
39
|
+
sorry: 0
|
40
|
+
|
41
|
+
Your code is a bit fucked up 💩
|
42
|
+
```
|
43
|
+
|
44
|
+
To limit the search to certain file types add the `--filetypes` parameter with a comma-delimited list of file extensions:
|
45
|
+
|
46
|
+
```
|
47
|
+
$ codefuckery --filetypes html,css,js path/to/your/source
|
48
|
+
```
|
49
|
+
|
50
|
+
`codefuckery` lets you customize the word list:
|
51
|
+
|
52
|
+
```
|
53
|
+
$ codefuckery --words fixme,todo,refactor path/to/your/source
|
54
|
+
```
|
55
|
+
|
56
|
+
Use regular expressions for really powerful searches for really fuuuuucked up situations. This will find comments like `// This code is shiiiit. Sooorrrry for fuuuucking up so bad`
|
57
|
+
|
58
|
+
```
|
59
|
+
$ codefuckery --words fu+ck,shi+t,so+rr+y path/to/your/source
|
60
|
+
```
|
61
|
+
|
62
|
+
If you want to limit the search to the specified directory only (excluding sub-directories) provide the `--no-recursive` option:
|
63
|
+
|
64
|
+
```
|
65
|
+
$ codefuckery --no-recursive path/to/your/source
|
66
|
+
```
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
Feel free to contribute to `codefuckery`. Just submit a pull request with your suggestion. If you find any bugs please open a [new GitHub issue](https://github.com/martinhoeller/codefuckery/issues/new).
|
data/Rakefile
ADDED
data/bin/codefuckery
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'clamp'
|
4
|
+
require_relative '../lib/codefuckery'
|
5
|
+
|
6
|
+
Clamp do
|
7
|
+
parameter "DIRECTORY", "Source directory to be checked", :attribute_name => :directory
|
8
|
+
|
9
|
+
option ["--filetypes", "-f"], "FILETYPES", "Comma-delimited list of file types, e.g.: rb,java,swift. By default all files are checked.", default: '' do |s|
|
10
|
+
s.split(/\s*,\s*/).map { |ext| ".#{ext}"}
|
11
|
+
end
|
12
|
+
|
13
|
+
option ["--words", "-w"], "WORDS", "Comma-delimited list of words to count, e.g.: fixme,fuck,refactor. (default: \"fuck,shit,sorry\")" do |s|
|
14
|
+
s.split(/\s*,\s*/)
|
15
|
+
end
|
16
|
+
|
17
|
+
option ["--[no-]recursive"], :flag, "Recursively check files in DIRECTORY and all sub-directories.", default: true
|
18
|
+
|
19
|
+
option ["--version", "-v"], :flag, "Shows codefuckery version" do
|
20
|
+
puts "codefuckery #{Codefuckery::VERSION}"
|
21
|
+
exit(0)
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute
|
25
|
+
word_counts = Codefuckery::Counter.count(directory, filetypes, words, recursive?)
|
26
|
+
|
27
|
+
if word_counts == nil
|
28
|
+
exit(-1)
|
29
|
+
end
|
30
|
+
|
31
|
+
print_results(word_counts)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def print_results(word_counts)
|
36
|
+
total_count = 0
|
37
|
+
word_counts.each { |word,count|
|
38
|
+
puts " #{word}: #{count}"
|
39
|
+
total_count += count
|
40
|
+
}
|
41
|
+
|
42
|
+
puts ""
|
43
|
+
if total_count == 0
|
44
|
+
puts "You have a wholesome codebase 🙏"
|
45
|
+
else
|
46
|
+
puts "Your code is a bit fucked up 💩"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/codefuckery.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'codefuckery/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'codefuckery'
|
8
|
+
s.version = Codefuckery::VERSION
|
9
|
+
s.date = '2019-11-09'
|
10
|
+
s.summary = 'Measure how fucked-up your code is'
|
11
|
+
s.description = 'Counts the occurrences of swearwords in your code.'
|
12
|
+
s.authors = ['Martin Höller']
|
13
|
+
s.email = 'martin@martinhoeller.net'
|
14
|
+
s.homepage = 'https://github.com/martinhoeller/codefuckery'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.files = `git ls-files -z`.split("\x0")
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
|
21
|
+
s.add_dependency 'clamp', '~> 1.3'
|
22
|
+
s.add_development_dependency 'rake'
|
23
|
+
s.add_development_dependency 'minitest'
|
24
|
+
end
|
data/lib/codefuckery.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module Codefuckery
|
2
|
+
class Counter
|
3
|
+
def self.count(directory, filetypes, words, recursive)
|
4
|
+
if !File.exists?(directory)
|
5
|
+
puts "ERROR: '#{directory}' does not exist"
|
6
|
+
return nil
|
7
|
+
end
|
8
|
+
|
9
|
+
if !File.directory?(directory)
|
10
|
+
puts "ERROR: '#{directory}' is not a directory"
|
11
|
+
return nil
|
12
|
+
end
|
13
|
+
|
14
|
+
paths = create_paths(directory, filetypes, recursive)
|
15
|
+
|
16
|
+
if words == nil || words.empty?
|
17
|
+
words = Codefuckery::DEFAULT_WORDS
|
18
|
+
end
|
19
|
+
|
20
|
+
word_counts = {}
|
21
|
+
words.each { |w| word_counts[w] = 0 }
|
22
|
+
paths.each { |p| count_in_file(p, words, word_counts) }
|
23
|
+
|
24
|
+
word_counts
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def self.create_paths(directory, filetypes, recursive)
|
29
|
+
expanded_directory = File.expand_path(directory)
|
30
|
+
pattern = recursive ? '**/*' : '**'
|
31
|
+
Dir.glob("#{expanded_directory}/#{pattern}").select { |fn| should_include(fn, filetypes) }
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def self.should_include(file, filetypes)
|
36
|
+
basename = File.basename(file)
|
37
|
+
if ['..', '.', '.git', '__MACOSX', '.DS_Store'].include? basename
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
|
41
|
+
if File.directory?(file)
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
|
45
|
+
extension = File.extname(file).strip.downcase
|
46
|
+
should_include = true
|
47
|
+
if !filetypes.empty?
|
48
|
+
should_include = !extension.empty? && (filetypes.include? extension)
|
49
|
+
end
|
50
|
+
|
51
|
+
should_include
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def self.count_in_file(file, words, word_counts)
|
56
|
+
data = File.read(file).force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
|
57
|
+
words.each { |w| word_counts[w] += data.scan(/#{w}/i).count }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'codefuckery'
|
3
|
+
|
4
|
+
describe Codefuckery::Counter do
|
5
|
+
describe "when directory does not exist" do
|
6
|
+
it "must return nil" do
|
7
|
+
File.stub :exists?, false do
|
8
|
+
assert_nil Codefuckery::Counter.count('dir', [], [], false)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "when directory is not a directory" do
|
14
|
+
it "must return nil" do
|
15
|
+
File.stub :directory?, false do
|
16
|
+
assert_nil Codefuckery::Counter.count('dir', [], [], false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "given a list of file types" do
|
22
|
+
it "should only count the matching files" do
|
23
|
+
Dir.stub :glob, ['file1.x', 'file2.y', 'file3.z'] do
|
24
|
+
assert_equal ['file1.x', 'file2.y'],
|
25
|
+
Codefuckery::Counter.create_paths('dir', ['.x', '.y'], false)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "given a file with two occurences of poop" do
|
31
|
+
it "should return a count of 2 for the word poop" do
|
32
|
+
word_counts = {'poop' => 0}
|
33
|
+
|
34
|
+
File.stub :read, "this test is poop poop" do
|
35
|
+
Codefuckery::Counter.count_in_file('file', ['poop'], word_counts)
|
36
|
+
assert_equal 2, word_counts['poop']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "given an existing word count" do
|
42
|
+
it "should increase the count" do
|
43
|
+
word_counts = {'poop' => 1}
|
44
|
+
|
45
|
+
File.stub :read, "this test is poop poop" do
|
46
|
+
Codefuckery::Counter.count_in_file('file', ['poop'], word_counts)
|
47
|
+
assert_equal 3, word_counts['poop']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "given a word is a regex" do
|
53
|
+
it "should find all matching occurences" do
|
54
|
+
word_counts = {'poo+p' => 0}
|
55
|
+
|
56
|
+
File.stub :read, "this test is poop poooop" do
|
57
|
+
Codefuckery::Counter.count_in_file('file', ['poo+p'], word_counts)
|
58
|
+
assert_equal 2, word_counts['poo+p']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codefuckery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Höller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: clamp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Counts the occurrences of swearwords in your code.
|
56
|
+
email: martin@martinhoeller.net
|
57
|
+
executables:
|
58
|
+
- codefuckery
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/codefuckery
|
70
|
+
- codefuckery.gemspec
|
71
|
+
- lib/codefuckery.rb
|
72
|
+
- lib/codefuckery/counter.rb
|
73
|
+
- lib/codefuckery/default_words.rb
|
74
|
+
- lib/codefuckery/version.rb
|
75
|
+
- test/test_counter.rb
|
76
|
+
- test/test_default_words.rb
|
77
|
+
homepage: https://github.com/martinhoeller/codefuckery
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.0.3
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Measure how fucked-up your code is
|
100
|
+
test_files: []
|