mudguard 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.mudguard.yml +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +62 -9
- data/lib/mudguard/infrastructure/persistence/.mudguard.template.yml +6 -0
- data/lib/mudguard/infrastructure/persistence/policy_file.rb +2 -1
- data/lib/mudguard/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a7b56ba51f10b0d6d32fcb120599bc145b275076b30786b6955285f5da26668
|
4
|
+
data.tar.gz: ca75c47ff5f80584407bb0da9d56b64f7c9e1e65cc8f7fc8b377ea0e8d83fefa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9bd40c81779ed70c331c0d445b735edb3e561967e65fce1dc228a62ad86fd9298dfaa990d3bded3faec6191b5821204466c9ed29cdf89d12e9eee1678884d81
|
7
|
+
data.tar.gz: 427d86d72d87f73d11dedfbb7a35d42ead0145919bf85e32dd5c9055bc977a2dadb9be668f76a081e61f54510a6ebb4aa66e7f4b11746da1a222efde3ad5b760
|
data/.gitignore
CHANGED
data/.mudguard.yml
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
# Mudguard
|
2
2
|
|
3
|
-
|
3
|
+
**Mudguard** is a Ruby static code analyzer that investigates the coupling of modules in your source code. Mudguard
|
4
|
+
prevents your code from becoming a [Big ball of mud](http://www.laputan.org/mud/) and helps implementing and
|
5
|
+
maintaining an intended design.
|
4
6
|
|
5
|
-
|
7
|
+
Mudguard is inspired by
|
8
|
+
* [Rubocop](https://github.com/rubocop-hq/rubocop)
|
9
|
+
* Clean Architecture by Robert C. Martin (ISBN-13: 978-0-13-449416-6)
|
10
|
+
* having seen many larger code bases in a sorrow state
|
11
|
+
* my inability to efficiently break up application code into gems or rails engines
|
6
12
|
|
7
|
-
|
13
|
+
# Installation
|
8
14
|
|
9
15
|
Add this line to your application's Gemfile:
|
10
16
|
|
@@ -20,19 +26,66 @@ Or install it yourself as:
|
|
20
26
|
|
21
27
|
$ gem install mudguard
|
22
28
|
|
23
|
-
##
|
29
|
+
## Quickstart
|
30
|
+
```
|
31
|
+
$ cd my/cool/ruby/project
|
32
|
+
$ mudguard
|
33
|
+
```
|
34
|
+
|
35
|
+
Mudguard creates on it's first run a file called **.mudguard.yml** which is used to configure **design policies**
|
36
|
+
governing your code. A .mudguard.yml could look like:
|
37
|
+
```
|
38
|
+
'./**/*.rb': # all code
|
39
|
+
# all code can depend on siblings in same module or class
|
40
|
+
- ^(::.+)(::[^:]+)* -> \1(::[^:]+)*$
|
41
|
+
# all code can depend on certain types
|
42
|
+
- .* -> ::(String|SecureRandom|Container|Time|Date|JSON|Object|Hash)$
|
43
|
+
|
44
|
+
# in all code module Application can depend on module Domain
|
45
|
+
- ^::Application(::[^:]+)* -> ::(Domain)(::[^:]+)*$
|
46
|
+
# in all code module Infrastructure can depend on module Application
|
47
|
+
- ^::Infrastructure(::[^:]+)* -> ::(Application)(::[^:]+)*$
|
48
|
+
|
49
|
+
'spec/**/*.rb': # spec code
|
50
|
+
# Only in test code can we use RSpec, Timecop and Exception
|
51
|
+
- .* -> ::(RSpec|Timecop|Exception)$
|
52
|
+
```
|
53
|
+
|
54
|
+
## The .mudguard.yml
|
55
|
+
The .mudguard.yml defines scopes and policies. A policy defines which dependencies are inside that scope permissible:
|
56
|
+
```
|
57
|
+
scope1:
|
58
|
+
- policy 1
|
59
|
+
- policy 2
|
60
|
+
scope2:
|
61
|
+
- policy 3
|
62
|
+
```
|
63
|
+
The **scope** is a [glob-pattern](https://en.wikipedia.org/wiki/Glob_(programming)) and defines to which files a set
|
64
|
+
of policies apply. For example a value `lib/docker/**/*.rb` defines a scope containing all Ruby files inside
|
65
|
+
folder lib/docker.
|
24
66
|
|
25
|
-
|
67
|
+
A **policy** is a [regular expression](https://ruby-doc.org/core-2.5.1/Regexp.html) matching one or a set of
|
68
|
+
dependencies that are permissible inside that scope. Mudguard represents a **dependency** as a symbol in form
|
69
|
+
of `X -> Y` meaning "X depends on Y". See following examples:
|
26
70
|
|
27
|
-
|
71
|
+
| Policy | matched Dependency| Explanation |
|
72
|
+
| --- | --- | --- |
|
73
|
+
| `^::A -> ::B$` | `::A -> ::B` |Module A can depend on module or constant B |
|
74
|
+
| `^::Infrastructure -> ::Rails$` | `::Infrastructure -> ::Rails` |Module Infrastructure can depend on Rails |
|
75
|
+
| `^::Infrastructure(::[^:]+)* -> ::ActiveRecord$` | `::Infrastructure::Logger -> ::ActiveRecord` or `::Infrastructure::Persistence -> ::ActiveRecord`|Module Infrastructure and its submodules can depend on ActiveRecord |
|
76
|
+
| `.* -> ::Exception$` | `::Api::Gateway -> ::Exception` or `::Logger -> ::Gateway` |Any module can depend on class Exception |
|
28
77
|
|
29
|
-
|
78
|
+
Any dependency for which Mudguard doesn't find a matching policy is reported as an impermissible dependency.
|
30
79
|
|
31
|
-
|
80
|
+
## Outlook
|
81
|
+
Using regular expressions as policies is very flexible but difficult to use. Furthermore certain patterns used in
|
82
|
+
the regular expressions do repeat. It might be useful to replace regular expressions in future with a specific language
|
83
|
+
to describe permissible dependencies. Any thoughts on that?
|
32
84
|
|
33
85
|
## Contributing
|
34
86
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Enceradeira/mudguard.
|
88
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
89
|
|
37
90
|
## License
|
38
91
|
|
@@ -15,7 +15,8 @@ module Mudguard
|
|
15
15
|
policy_exists = File.exist?(policy_file)
|
16
16
|
|
17
17
|
unless policy_exists
|
18
|
-
|
18
|
+
template_file = File.join(__dir__, ".mudguard.template.yml")
|
19
|
+
FileUtils.cp(template_file, policy_file)
|
19
20
|
end
|
20
21
|
|
21
22
|
read_yml(policy_file)
|
data/lib/mudguard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mudguard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jorg Jenni
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -174,6 +174,7 @@ extra_rdoc_files: []
|
|
174
174
|
files:
|
175
175
|
- ".envrc"
|
176
176
|
- ".gitignore"
|
177
|
+
- ".mudguard.yml"
|
177
178
|
- ".rubocop.yml"
|
178
179
|
- ".ruby-version"
|
179
180
|
- CODE_OF_CONDUCT.md
|
@@ -200,6 +201,7 @@ files:
|
|
200
201
|
- lib/mudguard/infrastructure/cli/controller.rb
|
201
202
|
- lib/mudguard/infrastructure/cli/notification_adapter.rb
|
202
203
|
- lib/mudguard/infrastructure/cli/view.rb
|
204
|
+
- lib/mudguard/infrastructure/persistence/.mudguard.template.yml
|
203
205
|
- lib/mudguard/infrastructure/persistence/policy_file.rb
|
204
206
|
- lib/mudguard/infrastructure/persistence/project_repository.rb
|
205
207
|
- lib/mudguard/infrastructure/persistence/ruby_files.rb
|