Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilenameBear: Add ignore_uppercase_filenames #687

Merged
merged 1 commit into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bears/general/FilenameBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class FilenameBear(LocalBear):
"pascal": to_pascalcase,
"snake": to_snakecase}

def run(self, filename, file, file_naming_convention: str="snake"):
def run(self, filename, file,
file_naming_convention: str="snake",
ignore_uppercase_filenames: bool=True):
"""
Checks whether the filename follows a certain naming-convention.

Expand All @@ -26,6 +28,9 @@ def run(self, filename, file, file_naming_convention: str="snake"):
- ``camel`` (``thisIsCamelCase``)
- ``pascal`` (``ThisIsPascalCase``)
- ``snake`` (``this_is_snake_case``)
:param ignore_uppercase_filenames:
Whether or not to ignore fully uppercase filenames completely,
e.g. COPYING, LICENSE etc.
"""
head, tail = os.path.split(filename)
filename_without_extension, extension = os.path.splitext(tail)
Expand All @@ -37,6 +42,9 @@ def run(self, filename, file, file_naming_convention: str="snake"):
file_naming_convention)
return

if ignore_uppercase_filenames and filename_without_extension.isupper():
return

if new_name != filename_without_extension:
diff = Diff(file, rename=os.path.join(head, new_name + extension))

Expand Down
7 changes: 7 additions & 0 deletions tests/general/FilenameBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ def test_pascal_case(self):
valid=False)
self.check_validity(self.uut, [""], filename="XYZ/__Init__.py")
self.check_validity(self.uut, [""], filename="/a/PascalCase")

def test_ignore_upper(self):
self.check_validity(self.uut, [""], filename='/LICENSE')

self.section['ignore_uppercase_filenames'] = 'nope'

self.check_validity(self.uut, [""], filename='/LICENSE', valid=False)