tidy-file-organizer 1.0.0
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/.github/workflows/ci.yml +47 -0
- data/.rspec +1 -0
- data/.rubocop.cookpad-styleguide.yml +373 -0
- data/.rubocop.yml +25 -0
- data/CLAUDE.md +139 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +102 -0
- data/README.ja.md +222 -0
- data/README.md +222 -0
- data/config/default.ja.yml +92 -0
- data/config/default.yml +92 -0
- data/exe/tidyify +5 -0
- data/lib/tidy_file_organizer/cli.rb +99 -0
- data/lib/tidy_file_organizer/config.rb +122 -0
- data/lib/tidy_file_organizer/date_organizer.rb +72 -0
- data/lib/tidy_file_organizer/duplicate_detector.rb +197 -0
- data/lib/tidy_file_organizer/duplicate_display.rb +104 -0
- data/lib/tidy_file_organizer/file_helper.rb +57 -0
- data/lib/tidy_file_organizer/file_mover.rb +57 -0
- data/lib/tidy_file_organizer/i18n.rb +43 -0
- data/lib/tidy_file_organizer/locale/en.yml +110 -0
- data/lib/tidy_file_organizer/locale/ja.yml +110 -0
- data/lib/tidy_file_organizer/organizer.rb +117 -0
- data/lib/tidy_file_organizer/post_install.rb +31 -0
- data/lib/tidy_file_organizer/setup_prompt.rb +194 -0
- data/lib/tidy_file_organizer/version.rb +3 -0
- data/lib/tidy_file_organizer.rb +15 -0
- data/tidy-file-organizer.gemspec +49 -0
- metadata +147 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c57f4ff4607299dc2428d31402431acb3f60b3cb963d44497f0c943c1fecd47f
|
|
4
|
+
data.tar.gz: 45a7990282a820f291ed8255bd8f2c8599135ad014d0d0cb77784c66d1f6070a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ec97357b083271eabf5ebed0aa18d991f55e4eb7f3729b790de333bf13e0d819254e305cd44c9e2d2da12582b95ec2e423d767e2c5517bf66e38742d0e9d4d6b
|
|
7
|
+
data.tar.gz: 34629074004913f1289c79d7b354325fa310cd25f5d2daa3473a4b6194e0ae8f24aba308909af96f09ad7aa43773638a2d82bc9b80a201af396e9e96cd54aefe
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
ruby-version: ['3.0', '3.1', '3.2', '3.3']
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Ruby
|
|
20
|
+
uses: ruby/setup-ruby@v1
|
|
21
|
+
with:
|
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
23
|
+
bundler-cache: true
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: bundle install
|
|
27
|
+
|
|
28
|
+
- name: Run tests
|
|
29
|
+
run: bundle exec rspec
|
|
30
|
+
|
|
31
|
+
lint:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v4
|
|
36
|
+
|
|
37
|
+
- name: Set up Ruby
|
|
38
|
+
uses: ruby/setup-ruby@v1
|
|
39
|
+
with:
|
|
40
|
+
ruby-version: '3.3'
|
|
41
|
+
bundler-cache: true
|
|
42
|
+
|
|
43
|
+
- name: Install dependencies
|
|
44
|
+
run: bundle install
|
|
45
|
+
|
|
46
|
+
- name: Run RuboCop
|
|
47
|
+
run: bundle exec rubocop
|
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# This RuboCop configuration is based on Cookpad's Ruby Style Guide
|
|
2
|
+
# Source: https://github.com/cookpad/styleguide
|
|
3
|
+
# License: CC BY 3.0 (https://creativecommons.org/licenses/by/3.0/)
|
|
4
|
+
#
|
|
5
|
+
# Modifications have been made for this project.
|
|
6
|
+
|
|
7
|
+
AllCops:
|
|
8
|
+
DisabledByDefault: true
|
|
9
|
+
DisplayCopNames: true
|
|
10
|
+
Exclude:
|
|
11
|
+
- vendor/**/*
|
|
12
|
+
- db/**/*
|
|
13
|
+
- bin/**
|
|
14
|
+
- node_modules/**/*
|
|
15
|
+
|
|
16
|
+
########################
|
|
17
|
+
# Ruby version
|
|
18
|
+
########################
|
|
19
|
+
|
|
20
|
+
# [SHOULD] Projects using Ruby 2.0 should prefer Ruby 2.0 syntax where possible: e.g. keyword arguments, symbol array literal notation(%i).
|
|
21
|
+
|
|
22
|
+
########################
|
|
23
|
+
# Indentation
|
|
24
|
+
########################
|
|
25
|
+
|
|
26
|
+
# [MUST] Use two spaces for 1-level of indent. Do not use the horizontal tab character.
|
|
27
|
+
Layout/IndentationStyle:
|
|
28
|
+
EnforcedStyle: spaces
|
|
29
|
+
Layout/IndentationWidth:
|
|
30
|
+
Enabled: true
|
|
31
|
+
Layout/IndentationConsistency:
|
|
32
|
+
Enabled: true
|
|
33
|
+
Layout/InitialIndentation:
|
|
34
|
+
Enabled: true
|
|
35
|
+
Layout/CommentIndentation:
|
|
36
|
+
Enabled: true
|
|
37
|
+
|
|
38
|
+
# [MUST] When you want to pass a block in the last method call of a long method chain, you must extract the receiver of the last method call into a local variable. Afterwards, write the method call with block as a separate statement on the following line.
|
|
39
|
+
|
|
40
|
+
# [SHOULD] When breaking an expression over multiple lines, you must increase the indentation level.
|
|
41
|
+
|
|
42
|
+
########################
|
|
43
|
+
# Whitespace
|
|
44
|
+
########################
|
|
45
|
+
|
|
46
|
+
# [MUST] Do not put whitespace at the end of a line.
|
|
47
|
+
Layout/TrailingWhitespace:
|
|
48
|
+
Enabled: true
|
|
49
|
+
|
|
50
|
+
########################
|
|
51
|
+
# Empty lines
|
|
52
|
+
########################
|
|
53
|
+
|
|
54
|
+
# [MUST] Leave exactly one newline at the end of a file.
|
|
55
|
+
Layout/TrailingEmptyLines:
|
|
56
|
+
EnforcedStyle: final_newline
|
|
57
|
+
|
|
58
|
+
########################
|
|
59
|
+
# Character encoding and magic comments
|
|
60
|
+
########################
|
|
61
|
+
|
|
62
|
+
# [MUST] Use UTF-8 as scripts' character encoding for no particular reason.
|
|
63
|
+
|
|
64
|
+
# [SHOULD] Do not use magic comments on Ruby 2.0+ and UTF-8 encoding because UTF-8 is the default encoding after Ruby 2.0.
|
|
65
|
+
|
|
66
|
+
# [MUST] Use the following style for magic comments when you need.
|
|
67
|
+
|
|
68
|
+
########################
|
|
69
|
+
# Line columns
|
|
70
|
+
########################
|
|
71
|
+
|
|
72
|
+
# [SHOULD] Keep lines shorter than 128 characters.
|
|
73
|
+
Layout/LineLength:
|
|
74
|
+
Max: 128
|
|
75
|
+
|
|
76
|
+
########################
|
|
77
|
+
# Numbers
|
|
78
|
+
########################
|
|
79
|
+
|
|
80
|
+
# [SHOULD] Use underscores to separate every three-digits when writing long numbers.
|
|
81
|
+
Style/NumericLiterals:
|
|
82
|
+
MinDigits: 7
|
|
83
|
+
Strict: true
|
|
84
|
+
|
|
85
|
+
# [SHOULD] Use underscores to separate every four-digits when writing long binary and hexadecimal numbers.
|
|
86
|
+
|
|
87
|
+
# [SHOULD] Do not mix uppercase and lowercase letters in hexadecimal numbers.
|
|
88
|
+
|
|
89
|
+
# [SHOULD] Use `r` suffix to write fractional numbers, if you are using Ruby 2.1+
|
|
90
|
+
|
|
91
|
+
# [SHOULD] Use `Integer#quo` method for writing fractional numbers, if you are using Ruby 2.0+
|
|
92
|
+
|
|
93
|
+
# [SHOULD] Use `i` or `ri` suffix to write complex numbers, if you are using Ruby 2.1+
|
|
94
|
+
|
|
95
|
+
########################
|
|
96
|
+
# Strings
|
|
97
|
+
########################
|
|
98
|
+
|
|
99
|
+
# [SHOULD] Use `''` to write empty strings.
|
|
100
|
+
Style/EmptyLiteral:
|
|
101
|
+
Enabled: true
|
|
102
|
+
|
|
103
|
+
# [SHOULD] Do not use `String.new` method with no arguments, unless there is a valid reason.
|
|
104
|
+
|
|
105
|
+
# [MUST] Use appropriate punctuation characters to minimize the number of escape sequences in string contents.
|
|
106
|
+
|
|
107
|
+
# [SHOULD] Use parentheses to write strings by `%` notation. You can use any kind of parentheses. In the following cases you can use non-parentheses characters for punctuations.
|
|
108
|
+
Style/PercentLiteralDelimiters:
|
|
109
|
+
Enabled: false
|
|
110
|
+
|
|
111
|
+
# [MUST] Do not write only `Object#to_s` in string interpolation, such as `"#{obj.to_s}"`.
|
|
112
|
+
Style/RedundantInterpolation:
|
|
113
|
+
Enabled: true
|
|
114
|
+
|
|
115
|
+
# [SHOULD] (Ruby 1.9+) Use `\u` notation to write Unicode characters rather than writing the bytes in `\x`, e.g. `"\u{3333}"` instead of `"\xE3\x8C\xB3"`. If you have to write a script for both Ruby 1.8 and 1.9, you may write the bytes in `\x` form.
|
|
116
|
+
|
|
117
|
+
# [SHOULD] Do not write string literals in loops (e.g. `while`, `until`, `for`).
|
|
118
|
+
|
|
119
|
+
# [SHOULD] Do not use `String#+` to concatenate any string objects to string literals. Use string interpolations.
|
|
120
|
+
|
|
121
|
+
# [MUST] Do not use `+=` to append string to string in a destructive manner. Use `String#<<` or `String#concat`.
|
|
122
|
+
|
|
123
|
+
########################
|
|
124
|
+
# Arrays
|
|
125
|
+
########################
|
|
126
|
+
|
|
127
|
+
# [MUST] If you write an array literal just after an assignment operator such as `=`, obey the following form denoted as "good".
|
|
128
|
+
Layout/MultilineArrayBraceLayout:
|
|
129
|
+
EnforcedStyle: symmetrical
|
|
130
|
+
|
|
131
|
+
# [SHOULD] In the multi-line array literal, put `,` after the last item.
|
|
132
|
+
Style/TrailingCommaInArrayLiteral:
|
|
133
|
+
EnforcedStyleForMultiline: consistent_comma
|
|
134
|
+
|
|
135
|
+
# [SHOULD] Use general delimited input (percent) syntax `%w(...)` or `%W(...)` for word arrays.
|
|
136
|
+
Style/WordArray:
|
|
137
|
+
EnforcedStyle: percent
|
|
138
|
+
|
|
139
|
+
# [MUST] Use `[]` to write empty arrays.
|
|
140
|
+
# (already definied above)
|
|
141
|
+
# Style/EmptyLiteral:
|
|
142
|
+
# Enabled: true
|
|
143
|
+
|
|
144
|
+
# [MUST] Do not use `Array.new` without any arguments.
|
|
145
|
+
|
|
146
|
+
# [SHOULD] Use `Array.new(n, obj)` to generate an array with `n` same items. Do not use `[obj] n` to reduce object allocation.
|
|
147
|
+
|
|
148
|
+
# [SHOULD] Use `[range]` form instead of `Range#to_a` to convert range literals to arrays.
|
|
149
|
+
|
|
150
|
+
########################
|
|
151
|
+
# Hashes
|
|
152
|
+
########################
|
|
153
|
+
|
|
154
|
+
# [MUST] Put whitespaces between `{` and the first key, and between the last value and `}` when writing hash literals on a single line.
|
|
155
|
+
Layout/SpaceInsideHashLiteralBraces:
|
|
156
|
+
EnforcedStyle: space
|
|
157
|
+
|
|
158
|
+
# [MUST] Use new hash syntax in Ruby 1.9+ (`{ foo: 42 }`) if all keys can be written in that syntax:
|
|
159
|
+
Style/HashSyntax:
|
|
160
|
+
EnforcedStyle: ruby19
|
|
161
|
+
|
|
162
|
+
# [SHOULD] Use hash rocket (`{ :foo => 42 }`) for all keys if any of keys can't be written in new Hash syntax (e.g. `:'foo.bar'`, `:'foo-bar'`, `if`, `unless`)
|
|
163
|
+
|
|
164
|
+
# [MUST] Use `{}` to write empty hashes.
|
|
165
|
+
# (already definied above)
|
|
166
|
+
# Style/EmptyLiteral:
|
|
167
|
+
# Enabled: true
|
|
168
|
+
|
|
169
|
+
# [MUST] If you write a hash literal just after an assignment operator, such as `=`, obey the following form denoted as "good".
|
|
170
|
+
# [SHOULD] In the multi line hash literal, put `,` after the last item.
|
|
171
|
+
Style/TrailingCommaInHashLiteral:
|
|
172
|
+
EnforcedStyleForMultiline: consistent_comma
|
|
173
|
+
|
|
174
|
+
# [SHOULD] If Symbol literals can be used as keys of hashes, use it for faster item lookup.
|
|
175
|
+
|
|
176
|
+
# [SHOULD] (Ruby 1.9+) If all the keys of hash literals are Symbol literals, use the form of `{ key: value }`. Put whitespace after `:`.
|
|
177
|
+
Layout/SpaceAfterColon:
|
|
178
|
+
Enabled: true
|
|
179
|
+
|
|
180
|
+
########################
|
|
181
|
+
# Operations
|
|
182
|
+
########################
|
|
183
|
+
|
|
184
|
+
# [SHOULD] Put whitespace around operators, except for `**`.
|
|
185
|
+
Layout/SpaceAroundOperators:
|
|
186
|
+
Enabled: true
|
|
187
|
+
|
|
188
|
+
# [MUST] Do not use `and`, `or`, and `not`.
|
|
189
|
+
Style/AndOr:
|
|
190
|
+
Enabled: true
|
|
191
|
+
|
|
192
|
+
# [MUST] Do not nest conditional operators.
|
|
193
|
+
Style/NestedTernaryOperator:
|
|
194
|
+
Enabled: true
|
|
195
|
+
|
|
196
|
+
# [MUST] Do not write conditional operators over multiple lines.
|
|
197
|
+
Style/MultilineTernaryOperator:
|
|
198
|
+
Enabled: true
|
|
199
|
+
|
|
200
|
+
########################
|
|
201
|
+
# Assignments
|
|
202
|
+
########################
|
|
203
|
+
|
|
204
|
+
# [MUST] Parallel assignments can only be used for assigning literal values or results of methods without arguments, and for exchanging two variables or attributes.
|
|
205
|
+
Style/ParallelAssignment:
|
|
206
|
+
Enabled: true
|
|
207
|
+
|
|
208
|
+
# [MUST] Put whitespace around assignment operators.
|
|
209
|
+
|
|
210
|
+
# [MUST] Do not write assignment expressions in conditional clauses.
|
|
211
|
+
Lint/AssignmentInCondition:
|
|
212
|
+
Enabled: true
|
|
213
|
+
AllowSafeAssignment: false
|
|
214
|
+
|
|
215
|
+
########################
|
|
216
|
+
# Control structures
|
|
217
|
+
########################
|
|
218
|
+
|
|
219
|
+
# [SHOULD] Use `unless condition`, instead of `if !condition`.
|
|
220
|
+
Style/NegatedIf:
|
|
221
|
+
Enabled: true
|
|
222
|
+
|
|
223
|
+
# [SHOULD] Use `until condition`, instead of `while !condition`.
|
|
224
|
+
Style/NegatedWhile:
|
|
225
|
+
Enabled: true
|
|
226
|
+
|
|
227
|
+
# [SHOULD] Do not use `else` for `unless`.
|
|
228
|
+
Style/UnlessElse:
|
|
229
|
+
Enabled: true
|
|
230
|
+
|
|
231
|
+
# [MUST] Put a line break just after the condition clause of `if`, `unless`, and `case`. Do not follow a body code.
|
|
232
|
+
|
|
233
|
+
# [MUST] Do not use `then` and `:` for the condition clause of `if`, `unless`, and `case`.
|
|
234
|
+
Style/WhenThen:
|
|
235
|
+
Enabled: true
|
|
236
|
+
|
|
237
|
+
# [MUST] Put a line break just after the condition clause of `while` and `until`. Do not follow a body code.
|
|
238
|
+
|
|
239
|
+
# [MUST] Do not use `do` and `:` for the condition clause of `while` and `until`.
|
|
240
|
+
Style/WhileUntilDo:
|
|
241
|
+
Enabled: true
|
|
242
|
+
|
|
243
|
+
# [SHOULD] Do not write a logical expressions combined by `||` in the condition clause of `unless` and `until`.
|
|
244
|
+
# [SHOULD] Use modifier forms, if conditions and bodies are short.
|
|
245
|
+
Style/WhileUntilModifier:
|
|
246
|
+
Enabled: true
|
|
247
|
+
|
|
248
|
+
# [SHOULD] Extract conditions as predicator methods with appropriate names if the conditions are long or multiple line.
|
|
249
|
+
|
|
250
|
+
# [MUST] If you write a control structure just after an assignment operator such as `=`, obey the following form denoted as "good".
|
|
251
|
+
|
|
252
|
+
# [MUST] Do not put any meaningless expressions after return, next, or break.
|
|
253
|
+
|
|
254
|
+
########################
|
|
255
|
+
# Method calls
|
|
256
|
+
########################
|
|
257
|
+
|
|
258
|
+
# [MUST] Do not omit parentheses of method calls except for the following permitted cases.
|
|
259
|
+
# Style/MethodCallWithoutArgsParentheses:
|
|
260
|
+
# Enabled: true
|
|
261
|
+
|
|
262
|
+
# [MUST] You must omit parentheses for method calls without any arguments.
|
|
263
|
+
# Style/MethodCallWithArgsParentheses:
|
|
264
|
+
# Enabled: true
|
|
265
|
+
|
|
266
|
+
# [MUST] For DSL-like methods (as in the examples below), you may omit parentheses when calling them. However, you should not omit parentheses for the case where the first argument is enclosed in parentheses, because this case generates syntax warning.
|
|
267
|
+
|
|
268
|
+
# [MUST] Do not put whitespace between a method name and parenthesis.
|
|
269
|
+
|
|
270
|
+
# [SHOULD] Due to separation of keyword and positional arguments in Ruby 3.0, distinguish between using keyword arguments and using a hash in method calls.
|
|
271
|
+
|
|
272
|
+
# [MUST] Use brace blocks `{ }` for a method call written in one line.
|
|
273
|
+
|
|
274
|
+
# [MUST] Use brace blocks `{ }` for multi-line blocks when chaining other method calls to itself.
|
|
275
|
+
|
|
276
|
+
# Style/BlockDelimiters:
|
|
277
|
+
# EnforcedStyle: braces_for_chaining
|
|
278
|
+
|
|
279
|
+
# [MUST] Obey the following "good" form in `do`/`end` form of blocks.
|
|
280
|
+
|
|
281
|
+
# [MUST] Put a whitespace before `{` of brace blocks.
|
|
282
|
+
Layout/SpaceBeforeBlockBraces:
|
|
283
|
+
EnforcedStyle: space
|
|
284
|
+
|
|
285
|
+
# [MUST] For a brace block written in one line, put whitespace between `{`, `}` and the inner contents.
|
|
286
|
+
Layout/SpaceInsideBlockBraces:
|
|
287
|
+
EnforcedStyle: space
|
|
288
|
+
|
|
289
|
+
# [SHOULD] On a method call with long parameters, write these arguments over multiple lines according to the following regulations.
|
|
290
|
+
|
|
291
|
+
########################
|
|
292
|
+
# BEGIN AND END
|
|
293
|
+
########################
|
|
294
|
+
|
|
295
|
+
# [MUST] Do not use `BEGIN` and `END` blocks.
|
|
296
|
+
Style/BeginBlock:
|
|
297
|
+
Enabled: true
|
|
298
|
+
Style/EndBlock:
|
|
299
|
+
Enabled: true
|
|
300
|
+
|
|
301
|
+
########################
|
|
302
|
+
# Module and Class definitions
|
|
303
|
+
########################
|
|
304
|
+
|
|
305
|
+
# [MUST] Use `alias_method` instead of `alias` to define aliases of methods.
|
|
306
|
+
Style/Alias:
|
|
307
|
+
EnforcedStyle: prefer_alias_method
|
|
308
|
+
|
|
309
|
+
# [MUST] use `attr_accessor`, `attr_reader`, and `attr_writer` to define accessors instead of `attr`.
|
|
310
|
+
Style/Attr:
|
|
311
|
+
Enabled: true
|
|
312
|
+
|
|
313
|
+
# [MUST] In definitions of class methods, use `self.` prefix of method name to reduce the indentation level. However, it is fine to use `class << self` when you want to define both public and private class methods.
|
|
314
|
+
Style/ClassMethods:
|
|
315
|
+
Enabled: true
|
|
316
|
+
|
|
317
|
+
# [MUST] In definitions of private or protected class methods, define these methods and change their visibilities in `class << self`/`end`.
|
|
318
|
+
|
|
319
|
+
# [MUST] If you use `private`, `protected`, and `public` with method name to change the visibilities of methods after definitions of the methods, do not put empty line between the definition of the method and these visibility-change methods.
|
|
320
|
+
|
|
321
|
+
# [MUST] If you use `private`, `protected`, and `public` without any arguments, align the lines of these method calls to their associated method definition. Put empty lines around the visibility-change methods.
|
|
322
|
+
Style/TrailingBodyOnMethodDefinition:
|
|
323
|
+
Enabled: true
|
|
324
|
+
|
|
325
|
+
# [SHOULD] Use Markdown format to write documentation comments for public interfaces of modules and/or classes.
|
|
326
|
+
|
|
327
|
+
# [SHOULD] Follow [YARD](http://yardoc.org/) style to write documentation comments.
|
|
328
|
+
|
|
329
|
+
# [MUST] Do not put empty lines between documentation comments and the corresponding method definitions.
|
|
330
|
+
|
|
331
|
+
# [MUST] Do not give different responsibilities to a class.
|
|
332
|
+
|
|
333
|
+
########################
|
|
334
|
+
# Method definitions
|
|
335
|
+
########################
|
|
336
|
+
|
|
337
|
+
# [MUST] On method definition, do not omit parentheses of parameter list, except for methods without parameters.
|
|
338
|
+
Style/MethodDefParentheses:
|
|
339
|
+
Enabled: true
|
|
340
|
+
|
|
341
|
+
# [MUST] Do not put whitespace between method name and the parameter list.
|
|
342
|
+
Layout/SpaceAfterMethodName:
|
|
343
|
+
Enabled: true
|
|
344
|
+
|
|
345
|
+
# [SHOULD] Do not write codes that is not understandable without any comment.
|
|
346
|
+
|
|
347
|
+
# [MUST] Do not give different responsibilities to a method.
|
|
348
|
+
|
|
349
|
+
# [MUST] Do not destructively modify arguments (i.e. cause side-effects).
|
|
350
|
+
|
|
351
|
+
########################
|
|
352
|
+
# Variables
|
|
353
|
+
########################
|
|
354
|
+
|
|
355
|
+
# [MUST] Do not introduce new global variables (`$foo`) for any reason.
|
|
356
|
+
Style/GlobalVars:
|
|
357
|
+
Enabled: true
|
|
358
|
+
|
|
359
|
+
# [MUST] Do not use class variables (`@@foo`) for any reasons. Use `class_attribute` instead.
|
|
360
|
+
Style/ClassVars:
|
|
361
|
+
Enabled: true
|
|
362
|
+
|
|
363
|
+
# [MUST] Name variables with valid English words without shortening. If a variable name gets too long, you can shorten the variable name by removing vowels, except for the first character. Alternatively, you choose well-known abbreviations. Additionally, you can use conventional variables such as `i` and `j` for loop counters.
|
|
364
|
+
|
|
365
|
+
# [SHOULD] Do not use a single variable for different purposes.
|
|
366
|
+
|
|
367
|
+
# [SHOULD] Minimize the scope of a local variable. Methods without any local variables are preferred.
|
|
368
|
+
|
|
369
|
+
########################
|
|
370
|
+
# Miscellaneous
|
|
371
|
+
########################
|
|
372
|
+
|
|
373
|
+
# [MUST] Keep the side effects of destructive methods to a minimum.
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# This project's RuboCop configuration
|
|
2
|
+
# Inherits from Cookpad's Ruby Style Guide and applies project-specific overrides
|
|
3
|
+
|
|
4
|
+
inherit_from: .rubocop.cookpad-styleguide.yml
|
|
5
|
+
|
|
6
|
+
# Additional plugins
|
|
7
|
+
plugins:
|
|
8
|
+
- rubocop-rspec
|
|
9
|
+
|
|
10
|
+
# Project-specific overrides
|
|
11
|
+
|
|
12
|
+
Metrics/ClassLength:
|
|
13
|
+
Max: 170
|
|
14
|
+
|
|
15
|
+
RSpec/MultipleExpectations:
|
|
16
|
+
Max: 10
|
|
17
|
+
|
|
18
|
+
RSpec/ContextWording:
|
|
19
|
+
Enabled: false
|
|
20
|
+
|
|
21
|
+
RSpec/SpecFilePathFormat:
|
|
22
|
+
Enabled: false
|
|
23
|
+
|
|
24
|
+
Gemspec/DevelopmentDependencies:
|
|
25
|
+
Enabled: false
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
A Ruby CLI tool that organizes files based on extensions, keywords, and dates. The tool supports internationalization (English/Japanese) based on the `LANG` environment variable and stores per-directory configurations using MD5 hashes.
|
|
8
|
+
|
|
9
|
+
## Development Commands
|
|
10
|
+
|
|
11
|
+
### Testing
|
|
12
|
+
```bash
|
|
13
|
+
# Run all tests
|
|
14
|
+
bundle exec rspec
|
|
15
|
+
|
|
16
|
+
# Run specific test file
|
|
17
|
+
bundle exec rspec spec/tidy_file_organizer_spec.rb
|
|
18
|
+
bundle exec rspec spec/duplicate_detector_spec.rb
|
|
19
|
+
bundle exec rspec spec/date_organizer_spec.rb
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Linting
|
|
23
|
+
```bash
|
|
24
|
+
# Run RuboCop
|
|
25
|
+
bundle exec rubocop
|
|
26
|
+
|
|
27
|
+
# Auto-fix issues
|
|
28
|
+
bundle exec rubocop -a
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Building and Installing
|
|
32
|
+
```bash
|
|
33
|
+
# Build gem
|
|
34
|
+
gem build tidy-file-organizer.gemspec
|
|
35
|
+
|
|
36
|
+
# Install locally
|
|
37
|
+
gem install ./tidy-file-organizer-*.gem
|
|
38
|
+
|
|
39
|
+
# Development mode (run without installing)
|
|
40
|
+
ruby -I lib ./exe/tidyify [command] [options]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Testing with Sample Data
|
|
44
|
+
```bash
|
|
45
|
+
# Test with English filenames
|
|
46
|
+
ruby -I lib ./exe/tidyify setup spec/data/en
|
|
47
|
+
ruby -I lib ./exe/tidyify run spec/data/en --recursive
|
|
48
|
+
|
|
49
|
+
# Test with Japanese filenames
|
|
50
|
+
ruby -I lib ./exe/tidyify setup spec/data/ja
|
|
51
|
+
ruby -I lib ./exe/tidyify run spec/data/ja --recursive
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Architecture
|
|
55
|
+
|
|
56
|
+
### Core Components
|
|
57
|
+
|
|
58
|
+
- **CLI** (`lib/tidy_file_organizer/cli.rb`): Entry point that parses commands and arguments. Handles 5 main commands:
|
|
59
|
+
- `setup` and `run`: Directory defaults to current directory if not specified
|
|
60
|
+
- `organize-by-date`, `find-duplicates`, `remove-duplicates`: Directory is required
|
|
61
|
+
- Options are parsed by checking for flags like `--dry-run`, `--recursive`/`-r`, `--pattern=<value>`, `--no-confirm`
|
|
62
|
+
|
|
63
|
+
- **Organizer** (`lib/tidy_file_organizer/organizer.rb`): Main orchestrator for file organization. Implements two-level priority system:
|
|
64
|
+
1. Keyword matching (higher priority) - matches keywords anywhere in filename
|
|
65
|
+
2. Extension matching (lower priority) - matches file extensions
|
|
66
|
+
|
|
67
|
+
- **Config** (`lib/tidy_file_organizer/config.rb`): Manages per-directory configuration using MD5 hash of directory path. Stores configs in `~/.config/tidy-file-organizer/[MD5hash].yml`. Supports default config references to avoid duplication.
|
|
68
|
+
|
|
69
|
+
- **I18n** (`lib/tidy_file_organizer/i18n.rb`): Internationalization system that auto-detects locale from `LANG` env var. Loads translations from `lib/tidy_file_organizer/locale/{en,ja}.yml`.
|
|
70
|
+
|
|
71
|
+
- **DateOrganizer** (`lib/tidy_file_organizer/date_organizer.rb`): Organizes files by modification date with three patterns: year, year-month, year-month-day.
|
|
72
|
+
|
|
73
|
+
- **DuplicateDetector** (`lib/tidy_file_organizer/duplicate_detector.rb`): Uses SHA-256 hashing to find and remove duplicate files. Supports interactive confirmation mode.
|
|
74
|
+
|
|
75
|
+
- **FileMover** (`lib/tidy_file_organizer/file_mover.rb`): Handles safe file movement with conflict detection and dry-run support.
|
|
76
|
+
|
|
77
|
+
- **FileHelper** (`lib/tidy_file_organizer/file_helper.rb`): Provides utilities for file collection, recursion, and path handling.
|
|
78
|
+
|
|
79
|
+
- **SetupPrompt** (`lib/tidy_file_organizer/setup_prompt.rb`): Interactive setup wizard that:
|
|
80
|
+
1. Prompts for language preference (en/ja)
|
|
81
|
+
2. Displays and accepts extension rules
|
|
82
|
+
3. Displays and accepts keyword rules
|
|
83
|
+
4. Provides language-specific default values in `default_extensions` and `default_keywords` methods
|
|
84
|
+
|
|
85
|
+
### Configuration System
|
|
86
|
+
|
|
87
|
+
Configurations are stored per-directory using MD5 hash of absolute path:
|
|
88
|
+
- Path: `~/.config/tidy-file-organizer/[MD5hash].yml`
|
|
89
|
+
- Default configs: `default.yml` (English), `default.ja.yml` (Japanese)
|
|
90
|
+
- If user config matches default, creates a reference file pointing to default instead of duplicating
|
|
91
|
+
|
|
92
|
+
Default configurations are sourced from `config/default.yml` and `config/default.ja.yml`.
|
|
93
|
+
|
|
94
|
+
**Configuration Format**:
|
|
95
|
+
```yaml
|
|
96
|
+
language: en # or 'ja'
|
|
97
|
+
extensions:
|
|
98
|
+
Images: [jpg, jpeg, png, gif, bmp, svg, webp]
|
|
99
|
+
Documents: [pdf, doc, docx, txt, md]
|
|
100
|
+
keywords:
|
|
101
|
+
Screenshots: [screenshot, スクリーンショット, スクショ]
|
|
102
|
+
Invoices: [invoice, 請求書]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Interactive Setup Input Format**: `extensions,list:directory keyword,list:directory`
|
|
106
|
+
- Example: `jpg,png:images pdf,doc:documents screenshot:screenshots`
|
|
107
|
+
|
|
108
|
+
**Language-Specific Defaults**: `SetupPrompt` maintains separate default configurations for English and Japanese. When language is set to 'ja', folder names use Japanese (e.g., '画像', '書類') while English uses 'Images', 'Documents'. Keywords include both languages to support bilingual file matching.
|
|
109
|
+
|
|
110
|
+
### Internationalization Flow
|
|
111
|
+
|
|
112
|
+
1. `I18n.locale` auto-detects from `LANG` environment variable (defaults to `:en`)
|
|
113
|
+
2. Translations loaded from `lib/tidy_file_organizer/locale/{locale}.yml`
|
|
114
|
+
3. All user-facing messages use `I18n.t('key.path')` for translation
|
|
115
|
+
4. Supports variable interpolation: `I18n.t('key', var: value)`
|
|
116
|
+
|
|
117
|
+
### File Organization Priority
|
|
118
|
+
|
|
119
|
+
When running `tidyify run`:
|
|
120
|
+
1. **Keyword matching** is checked first (entire filename)
|
|
121
|
+
2. **Extension matching** is checked second (file extension only)
|
|
122
|
+
3. Files matching neither are skipped
|
|
123
|
+
4. Organized directories are excluded from processing to prevent reorganizing already-organized files
|
|
124
|
+
|
|
125
|
+
**Exclusion Mechanism**:
|
|
126
|
+
- `Organizer#extract_organized_dirs` collects all directory names from config (both extensions and keywords)
|
|
127
|
+
- In recursive mode, `FileHelper#excluded_path?` checks if any part of the file's relative path matches an organized directory name
|
|
128
|
+
- This prevents files like `images/photo.jpg` from being re-organized into `images/images/photo.jpg`
|
|
129
|
+
- Empty directories are automatically cleaned up after recursive organization (excluding the target directory and organized directories)
|
|
130
|
+
|
|
131
|
+
## Code Style
|
|
132
|
+
|
|
133
|
+
This project follows [Cookpad's Ruby Style Guide](https://github.com/cookpad/styleguide) via `.rubocop.cookpad-styleguide.yml` with project-specific overrides in `.rubocop.yml`.
|
|
134
|
+
|
|
135
|
+
## Requirements
|
|
136
|
+
|
|
137
|
+
- Ruby 3.0+
|
|
138
|
+
- Standard library only (yaml, fileutils, digest)
|
|
139
|
+
- Development dependencies: rspec, rubocop, rubocop-performance, rubocop-rspec
|