|
1 | 1 | # codeclimate-duplication |
2 | 2 |
|
3 | 3 | `codeclimate-duplication` is an engine that wraps [flay] and supports Ruby, |
4 | | -Python, JavaScript, and PHP. You can run it in the command line using the Code |
5 | | -Climate CLI, or on our [hosted analysis platform][codeclimate]. |
6 | | - |
7 | | -[codeclimate]: https://codeclimate.com/dashboard |
| 4 | +Python, JavaScript, and PHP. You can run it on the command line using the Code |
| 5 | +Climate CLI or on our [hosted analysis platform][codeclimate]. |
8 | 6 |
|
9 | 7 | ## Installation |
10 | 8 |
|
11 | | -1. If you haven't already, [install the Code Climate CLI][cli] |
12 | | -2. Run `codeclimate engines:enable duplication`. This command both installs the |
13 | | - engine and enables it in your `.codeclimate.yml` file. |
14 | | -3. You're ready to analyze! Browse into your project's folder and run |
15 | | - `codeclimate analyze`. |
16 | | - |
17 | | -[flay]: https://github.com/seattlerb/flay |
18 | | -[cli]: https://github.com/codeclimate/codeclimate |
| 9 | +1. Install the [Code Climate CLI][cli], if you haven't already. |
| 10 | +2. Run `codeclimate engines:enable duplication`. This command installs the |
| 11 | + engine and enables it in your `.codeclimate.yml` file. |
| 12 | +3. You're ready to analyze! `cd` into your project's folder and run `codeclimate |
| 13 | + analyze`. |
19 | 14 |
|
20 | 15 | ## Configuring |
21 | 16 |
|
22 | | -You can add the following to your `.codeclimate.yml` to get started with the |
23 | | -duplication engine. |
| 17 | +### Languages |
| 18 | + |
| 19 | +By enabling the duplication engine with the Code Climate CLI, all supported |
| 20 | +languages are configured by default, but we recommend adjusting this |
| 21 | +configuration to enable only the languages you care about. If you have a project |
| 22 | +with Ruby and JavaScript files, you might want the following configuration: |
24 | 23 |
|
25 | 24 | ```yaml |
26 | 25 | engines: |
27 | 26 | duplication: |
28 | 27 | enabled: true |
29 | 28 | config: |
30 | 29 | languages: |
31 | | - YOUR_LANGUAGE: |
| 30 | + - ruby |
| 31 | + - javascript |
32 | 32 | ``` |
33 | 33 | |
34 | | -This will tell Code Climate to run the duplication engine with `YOUR_LANGUAGE`. |
35 | | -You can also specify a `paths` array under `YOUR_LANGUAGE` which use Ruby's |
36 | | -[`Dir.glob`][glob] format. |
37 | | - |
38 | | -For example, all JavaScript and JSX files: |
| 34 | +This will tell the duplication engine to analyze Ruby and JavaScript files. |
39 | 35 | |
40 | | -```yaml |
41 | | -engines: |
42 | | - duplication: |
43 | | - enabled: true |
44 | | - config: |
45 | | - languages: |
46 | | - javascript: |
47 | | - paths: |
48 | | - - "**/*.js" |
49 | | - - "**/*.jsx" |
50 | | -``` |
| 36 | +### Threshold |
51 | 37 | |
52 | | -[glob]: http://ruby-doc.org/core-1.9.3/Dir.html#method-c-glob |
| 38 | +We set useful threshold defaults for the languages we support but you may want |
| 39 | +to adjust these settings based on your project guidelines. |
53 | 40 | |
54 | | -You can also specify the mass threshold which is what determines how much "mass" |
55 | | -a block of code needs before it's checked for duplication. This varies from |
56 | | -language to language with higher numbers needing more mass to trigger a check |
57 | | -and lower numbers needing less mass. |
| 41 | +The threshold configuration represents the minimum "mass" a code block must have |
| 42 | +to be analyzed for duplication. If the engine is too easily reporting |
| 43 | +duplication, try raising the threshold. If you suspect that the engine isn't |
| 44 | +catching enough duplication, try lowering the threshold. The best setting tends |
| 45 | +to differ from language to language. |
58 | 46 | |
59 | | -For example you could tell the engine to check only very large blocks of code: |
| 47 | +To adjust this setting, add a `mass_threshold` key with your preferred value for |
| 48 | +an enabled language: |
60 | 49 |
|
61 | 50 | ```yaml |
62 | 51 | engines: |
63 | 52 | duplication: |
64 | 53 | enabled: true |
65 | 54 | config: |
66 | 55 | languages: |
| 56 | + ruby: |
| 57 | + mass_threshold: 20 |
67 | 58 | javascript: |
68 | | - mass_threshold: 300 |
69 | 59 | ``` |
| 60 | + |
| 61 | +Note that you have the update the YAML structure under the `langauges` key to |
| 62 | +the Hash type to support extra configuration. |
| 63 | + |
| 64 | +[codeclimate]: https://codeclimate.com/dashboard |
| 65 | +[flay]: https://github.com/seattlerb/flay |
| 66 | +[cli]: https://github.com/codeclimate/codeclimate |
0 commit comments