Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d9342714
Commit
d9342714
authored
Feb 11, 2020
by
Mikolaj Wawrzyniak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cop enforcing maximum filename length rule
parent
0bd8eed8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
rubocop/cop/filename_length.rb
rubocop/cop/filename_length.rb
+25
-0
spec/rubocop/cop/filename_length_spec.rb
spec/rubocop/cop/filename_length_spec.rb
+51
-0
No files found.
rubocop/cop/filename_length.rb
0 → 100644
View file @
d9342714
# frozen_string_literal: true
module
RuboCop
module
Cop
class
FilenameLength
<
Cop
include
RangeHelp
FILEPATH_MAX_BYTES
=
256
FILENAME_MAX_BYTES
=
100
MSG_FILEPATH_LEN
=
"This file path is too long. It should be
#{
FILEPATH_MAX_BYTES
}
or less"
MSG_FILENAME_LEN
=
"This file name is too long. It should be
#{
FILENAME_MAX_BYTES
}
or less"
def
investigate
(
processed_source
)
file_path
=
processed_source
.
file_path
return
if
config
.
file_to_exclude?
(
file_path
)
if
file_path
.
bytesize
>
FILEPATH_MAX_BYTES
add_offense
(
nil
,
location:
source_range
(
processed_source
.
buffer
,
1
,
0
,
1
),
message:
MSG_FILEPATH_LEN
)
elsif
File
.
basename
(
file_path
).
bytesize
>
FILENAME_MAX_BYTES
add_offense
(
nil
,
location:
source_range
(
processed_source
.
buffer
,
1
,
0
,
1
),
message:
MSG_FILENAME_LEN
)
end
end
end
end
end
spec/rubocop/cop/filename_length_spec.rb
0 → 100644
View file @
d9342714
# frozen_string_literal: true
require
'spec_helper'
require
'rubocop'
require
'rubocop/rspec/support'
require_relative
'../../../rubocop/cop/filename_length'
require_relative
'../../support/helpers/expect_offense'
describe
RuboCop
::
Cop
::
FilenameLength
do
subject
(
:cop
)
{
described_class
.
new
}
it
'does not flag files with names 100 characters long'
do
expect_no_offenses
(
'puts "it does not matter"'
,
'a'
*
100
)
end
it
'tags files with names 101 characters long'
do
filename
=
'a'
*
101
expect_offense
(
<<~
SOURCE
,
filename
)
source code
^ This file name is too long. It should be 100 or less
SOURCE
end
it
'tags files with names 256 characters long'
do
filename
=
'a'
*
256
expect_offense
(
<<~
SOURCE
,
filename
)
source code
^ This file name is too long. It should be 100 or less
SOURCE
end
it
'tags files with filepath 256 characters long'
do
filepath
=
File
.
join
'a'
,
'b'
*
254
expect_offense
(
<<~
SOURCE
,
filepath
)
source code
^ This file name is too long. It should be 100 or less
SOURCE
end
it
'tags files with filepath 257 characters long'
do
filepath
=
File
.
join
'a'
,
'b'
*
255
expect_offense
(
<<~
SOURCE
,
filepath
)
source code
^ This file path is too long. It should be 256 or less
SOURCE
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment