https://github.com/tamada/fritter
Small object programming/Object-oriented programming exercise checker.
https://github.com/tamada/fritter
code-quality-analyzer java-11 object-oriented-programming small-object-detection
Last synced: 10 months ago
JSON representation
Small object programming/Object-oriented programming exercise checker.
- Host: GitHub
- URL: https://github.com/tamada/fritter
- Owner: tamada
- License: apache-2.0
- Created: 2021-01-26T14:51:32.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-27T13:44:32.000Z (almost 5 years ago)
- Last Synced: 2023-03-22T16:29:43.432Z (almost 3 years ago)
- Topics: code-quality-analyzer, java-11, object-oriented-programming, small-object-detection
- Language: Java
- Homepage:
- Size: 505 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fritter
[](https://github.com/tamada/fritter/actions?query=workflow%3Abuild)
[](https://www.codacy.com/gh/tamada/fritter/dashboard?utm_source=github.com&utm_medium=referral&utm_content=tamada/fritter&utm_campaign=Badge_Grade)
[](https://codecov.io/gh/tamada/fritter)
[](https://coveralls.io/github/tamada/fritter?branch=main)
[](https://raw.githubusercontent.com/tamada/fritter/main/LICENSE)
[](https://github.com/tamada/fritter/releases/tag/v1.0.0)
[](https://github.com/users/tamada/packages/container/package/fritter)
[](https://github.com/tamada/homebrew-brew)
[](https://github.com/tamada/fritter/discussions)
Small object programming/Object oriented exercise checker.
This product extends [tamada/9rules](https://github.com/tamada/9rules).
The superior points of `fritter` than 9rules are as follows.
* Simplify the class relationships from 9rules.
* In the case of `9rules`, it becomes to complicated relationships among classes to satisfy the 9rules itself.
* Then, `fritter` prioritizes the understandability of the source codes even if to not satisfy the rules of itself.
* Introduce more rules, and ease to add more rules.
* This is the side effect of the above point.
* To introduce the new rule, we provide only two classes which are subclasses of `Validator` and `ValidatorService`.
* Ease to customize the parameters for validators.
* All parameters are read from configuration files.
* The configuration files are given by `--level` option or `--config` option. `fritter` defines the parameters by json formatted config file also `level`.
* Enable to select the output formats.
* `fritter` provides `json`, `xml`, and `markdown` format as result.
* Thread supports.
* `fritter` uses the threads by user requests for each analyzing target.
## Description
The book titled '[The ThoughtWorks Anthology: Essays on Software Technology and Innovation](https://pragprog.com/book/twa/thoughtworks-anthology)' are published.
Chapter 6 in the book introduces object calisthenics for better software design.
The rules shown in the book are as follows.
1. Use 1 level of indentation per method (`indent_level`), `DONE`
2. Do not use the `else` keyword (`no_else`), `DONE`
3. Wrap all primitives and strings (`primitive_wrapping`), `DONE`
4. Use only 1 dot per line (`one_dot_per_line`), `DONE`
5. Do not abbreviate (`no_abbrev`),
6. Keep all entities small,
* 50 lines in a source file (`lines_of_class`), `DONE`
* 3 lines in a method (`lines_of_method`), and `DONE`
* 10 classses in a package (`classes_in_package`).
7. Do not use any classes with more than 2 instance variables (`field_count`), `DONE`
8. Use first-class collections (`first_class_collection`), and `DONE`
9. Do not use any getters/setters/properties (`no_accessor`) `DONE`
Unfortunately, to confirm obeying the rules is by a human eye.
Therefore, this tool was developed to validate the rules automatically by analyzing given Java source codes.
By the way, this tool is programed to obey above rules.
### Additional rules
The following rules are the additional rules for more analysis.
10. Do not use any methods with more than 2 local variables (`local_variable_count`), `DONE`
11. Do not use `static` method except `main` method (`no_static_method`), `DONE`
12. Do not create an array (`no_new_array`), `DONE`
13. Do not use `System.exit` (`no_system_exit`) except `main` method, `DONE`
14. Do not use `\n` in the `printf` formatter (`no_return_code_in_printf`), and `DONE`
15. Do not use only single character in the variable name, except loop control variables (`single_character_name`). `DONE`
## Usage
```shell
Usage: fritter [-hinstV] [-c=CONFIG] [-f=FORMAT] [-l=LEVEL]
SOURCE_FILEs|SOURCE_DIRs...
Small object programming checker.
SOURCE_FILEs|SOURCE_DIRs...
Java source files and/or directories containing
Java source files.
-c, --config=CONFIG specifies the configuration file.
-f, --format=FORMAT specifies the resultant format. Default is json.
Available values: json, markdown, yaml, and xml
-h, --help Show this help message and exit.
-i, --no-validator-info does not show the validator information for
analyses.
-l, --level=LEVEL specifies the strict level. Default is default.
Available values: strict, general, rough, and
default.
-n, --no-summary does not show the summary of analysis.
-s, --show-no-violated-files
shows file names with no violations.
-t, --with-threads use threads for validations.
-V, --version Print version information and exit.
```
## Config format
The format of config file must be JSON, like as follows.
```json
{
"name": "default",
"validators": [
"indent_level",
"no_else",
"primitive_wrapping",
"dot_count_per_line",
"no_abbrev",
"lines_of_class",
"lines_of_method",
"classes_in_package",
"field_count",
"first_class_collection",
"no_accessor",
"variable_count",
"no_static_method",
"no_new_array",
"no_system_exit",
"no_return_code_in_printf",
"single_character_name"
],
"parameters": {
"indent_level": 1,
"dot_count_per_line": 1,
"lines_of_class": 50,
"lines_of_method": 3,
"classes_in_package": 10,
"field_count": 2,
"variable_count": 2
}
}
```
## Result example
### Json
The following json is validating `src/test/resources/projects/examples/HelloWorld.java` with no options, and formatted with `jq` command.
```json5
{
"date": "2021-02-01T23:37:08.966582",
"validators": [
"indent_level",
"no_else",
"primitive_wrapping",
"dot_count_per_line",
"lines_of_class",
"lines_of_method",
"field_count",
"first_class_collection",
"no_accessor",
"no_static_method",
"no_new_array",
"no_system_exit",
"no_return_code_in_printf",
"single_character_name"
],
"results": [
{
"base": "src/test/resources/projects/examples/HelloWorld.java",
"violations": [
{
"file": "",
"messages": [
{
"line": 10,
"key": "lines_of_method",
"message": "lines of method is 4, more than 3"
},
{
"line": 19,
"key": "lines_of_method",
"message": "lines of method is 4, more than 3"
},
{
"line": 15,
"key": "no_accessor",
"message": "getMessage: no getter method"
},
{
"line": 2,
"key": "no_static_method",
"message": "violatedMethod: no static method except main method"
},
{
"line": 12,
"key": "no_system_exit",
"message": "no System.exit except main method"
},
{
"line": 11,
"key": "no_return_code_in_printf",
"message": "no '\n', use '%n' in printf"
}
]
}
]
}
],
"summary": {
"violated-files": 1,
"total-files": 1,
"violated-file-count": 6
}
}
```
### Xml
The following xml is validating `src/test/resources/projects/examples/Primes.java` with `-f xml` options, and formatted with `xmllint` command (`xmllint --format -`).
```xml
indent_level
no_else
primitive_wrapping
dot_count_per_line
lines_of_class
lines_of_method
field_count
first_class_collection
no_accessor
no_static_method
no_new_array
no_system_exit
no_return_code_in_printf
single_character_name
src/test/resources/projects/examples/Primes.java
indent_level
17
print: indent level is 2, more than 1
indent_level
29
sieves: indent level is 2, more than 1
no_else
51
no else statement
lines_of_class
3
lines of class is 55, more than 50
lines_of_method
4
lines of method is 5, more than 3
lines_of_method
10
lines of method is 15, more than 3
lines_of_method
26
lines of method is 8, more than 3
lines_of_method
35
lines of method is 5, more than 3
lines_of_method
41
lines of method is 5, more than 3
lines_of_method
47
lines of method is 6, more than 3
no_new_array
42
do not use array, use List instead
1
1
11
```
### Markdown
The following markdown is validating `src/test/resources/projects/examples/StatsValues.java` with `-f markdown` options.
```markdown
# fritter results
Date: 2021-02-01T23:47:02.609847
## Validators
* indent_level
* no_else
* primitive_wrapping
* dot_count_per_line
* lines_of_class
* lines_of_method
* field_count
* first_class_collection
* no_accessor
* no_static_method
* no_new_array
* no_system_exit
* no_return_code_in_printf
* single_character_name
## Results
### src/test/resources/projects/examples/StatsValues.java
####
##### Violations
* indent_level (line: 23)
* print: indent level is 2, more than 1
* lines_of_method (line: 13)
* lines of method is 5, more than 3
* lines_of_method (line: 19)
* lines of method is 9, more than 3
* lines_of_method (line: 29)
* lines of method is 5, more than 3
* lines_of_method (line: 35)
* lines of method is 4, more than 3
* lines_of_method (line: 40)
* lines of method is 5, more than 3
* field_count (lines: 9, 10, 11)
* field count is 3, more than 2
* first_class_collection (lines: 9, 10, 11)
* not first class collection
## Summary
* violated files: 1
* total files: 1
* violated file count: 8
```