Repository: codespell-project/codespell

Issue:
Allow hidden files to be checked
Looking at the code for some other stuff, I found hidden files are silently skipped by default:
https://github.com/codespell-project/codespell/blob/50bcf82833aaae8f99fc9b82d886c7191c117e0c/codespell_lib/_codespell.py#L331-L338
and
https://github.com/codespell-project/codespell/blob/f9f8d1fcca90c521baee52f397e2b3fc7f37f94c/codespell_lib/_codespell.py#L625-L626

As a user, I may want to spellcheck hidden files (e.g. my Travis file or other hidden config). It would be nice if it logged if it was skipping them, and add a command line option to scan them too.


Discussion:
Arises from #283 

Resolving patch:
diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py
--- a/codespell_lib/_codespell.py
+++ b/codespell_lib/_codespell.py
@@ -280,6 +280,11 @@ def parse_options(args):
                       action='store_true', default=False,
                       help='Check file names as well.')
 
+    parser.add_option('-H', '--check-hidden',
+                      action='store_true', default=False,
+                      help='Check hidden files (those starting with ".") as '
+                           'well.')
+
     (o, args) = parser.parse_args(list(args))
 
     if not args:
@@ -332,7 +337,7 @@ def is_hidden(filename):
     bfilename = os.path.basename(filename)
 
     if bfilename != '' and bfilename != '.' and bfilename != '..' \
-                    and bfilename[0] == '.':
+                    and (not options.check_hidden and bfilename[0] == '.'):
         return True
 
     return False


Test patch:
diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py
--- a/codespell_lib/tests/test_basic.py
+++ b/codespell_lib/tests/test_basic.py
@@ -90,13 +90,6 @@ def test_basic():
         os.mkdir(op.join(d, 'test'))
         assert cs.main(d) == 0
 
-        # hidden file
-        with open(op.join(d, 'test.txt'), 'w') as f:
-            f.write('abandonned\n')
-        assert cs.main(op.join(d, 'test.txt')) == 1
-        os.rename(op.join(d, 'test.txt'), op.join(d, '.test.txt'))
-        assert cs.main(op.join(d, '.test.txt')) == 0
-
 
 def test_interactivity():
     """Test interaction"""
@@ -287,6 +280,23 @@ def test_check_filename():
         assert cs.main('-f', d) == 1
 
 
+def test_check_hidden():
+    """Test ignoring of hidden files"""
+    with TemporaryDirectory() as d:
+        # hidden file
+        with open(op.join(d, 'test.txt'), 'w') as f:
+            f.write('abandonned\n')
+        assert cs.main(op.join(d, 'test.txt')) == 1
+        os.rename(op.join(d, 'test.txt'), op.join(d, '.test.txt'))
+        assert cs.main(op.join(d, '.test.txt')) == 0
+        assert cs.main('--check-hidden', op.join(d, '.test.txt')) == 1
+        os.rename(op.join(d, '.test.txt'), op.join(d, '.abandonned.txt'))
+        assert cs.main(op.join(d, '.abandonned.txt')) == 0
+        assert cs.main('--check-hidden', op.join(d, '.abandonned.txt')) == 1
+        assert cs.main('--check-hidden', '--check-filenames',
+                       op.join(d, '.abandonned.txt')) == 2
+
+
 class TemporaryDirectory(object):
     """Backport for 2.7"""