GithubHelp home page GithubHelp logo

michaelaquilina / flake8-spellcheck Goto Github PK

View Code? Open in Web Editor NEW
71.0 5.0 28.0 1.37 MB

❄️ Spellcheck variables, classnames, comments, docstrings etc

License: MIT License

Python 98.49% Shell 1.51%
python linter spellcheck

flake8-spellcheck's Introduction

Flake8 Spellcheck

CircleCI Black PyPi

Flake8 Plugin that spellchecks variables, functions, classes and other bits of your python code.

You can whitelist words that are specific to your project simply by adding them to whitelist.txt in the root of your project directory. Each word you add should be separated by a newline.

Spelling is assumed to be in en_US.

This plugin supports python 3.8+

Codes

  • SC100 - Spelling error in comments
  • SC200 - Spelling error in name (e.g. variable, function, class)

Enable Django support

You can enable support for a Django dictionary by adding the following to your flake8 configuration (e.g. your .flake8 file):

[flake8]
dictionaries = en_US,python,technical,django

Enable pandas support

You can enable support for pandas DataFrames by adding the following to your flake8 configuration (e.g. your .flake8 file):

[flake8]
dictionaries = en_US,python,technical,pandas

Specify Targets

Both comments and names (variable names, function names...) are spellchecked by default. You can specify what targets to spellcheck in your flake8 configuration (e.g. in your .flake8 file):

[flake8]
spellcheck-targets = comments

The above configuration would only spellcheck comments

[flake8]
spellcheck-targets = names

The above configuration would only spellcheck names

Ignore Rules

[flake8]
ignore = SC100, SC200

Contributing

If you have found word(s) which are listed as a spelling error but are actually correct terms used in python or in technical implementations (e.g. http), then you can very easily contribute by adding those word(s) to the appropriate dictionaries:

Before you submit a PR, it is recommended to run check-sorting.sh in the root of this repository, to verify that all the dictionary files are still sorted correctly. Sorting is enforced by CI, so you'll need to make sure the files are sorted before your PR can be merged.

Development

  • Install poetry
  • Run poetry install
  • Run poetry run pre-commit install --install-hooks

You can run tests with poetry run pytest.

flake8-spellcheck's People

Contributors

aaronzipp avatar asears avatar brentwilkins avatar codertimeless avatar djmattyg007 avatar gaborbernat avatar gera avatar markfazekas avatar mattkatz avatar michaelaquilina avatar mondeja avatar papr avatar paulovcmedeiros avatar paulthomson avatar pbelskiy avatar shaleh avatar szepeviktor avatar tadaboody avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flake8-spellcheck's Issues

Improvements in word splitting

Just wondering if there is any reason why camel case words aren't always split when checking spelling.

In particular if there are camelcase words in a comment then they flag with SC100
But also if there is some terribly named variable like TestData_apple then SC200 will flag 'TestData' as a spelling error whereas I would have expected 'Test' and 'Data' to have been checked separately by flake8-spellcheck

The other word splitting choice I am curious about is "words" that have digits in them. I have an electronics library with a fairly ridiculous whitelist containing things like 100n, 10m, 10n5, 1n, 1k, 200m, 250V, 250VAC, 33R4, 470R, 6V3, etc, etc which is a bit cumbersome.

Edit: Another odd word splitting thing.
If I have pd.Timestamp('2017-06-01T12')) then everything is fine, however if I have # pd.Timestamp('2017-06-01T12')) then I get a misspelt word of '2017. I understand single quotes are really apostrophes (I have argued within my team for double quoted strings with no luck) so splitting up words on single quotes isn't possible, but it is a bit annoying having to put things like '2017 in my whitelist.

It's a segmentation error when dealing with quotation marks

In dictionary, class's -> classs
Cause typo 'classs' pass check.
Please fix this problem when you have time :)

# __init__.py lines of 118 # Hacky way of getting dictionary with symbols stripped self.no_symbols = set(w.replace("'", "") for w in self.words)

Can't work with python2.7

My Python version is 2.7, flake8 version is 3.5.0 (flake8-future-import: 0.4.5, mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 2.7.17 on Darwin
after i install flake8-spellcheck-0.9.1, it can't work anymore.

(mywork) loganlideMacBook-Pro:test $ flake8 test.py Traceback (most recent call last): File "/Users/timeless/.vitualenvs/mywork/bin/flake8", line 8, in <module> sys.exit(main()) File "/Users/timeless/.vitualenvs/mywork/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main app.run(argv) File "/Users/timeless/.vitualenvs/mywork/lib/python2.7/site-packages/flake8/main/application.py", line 396, in run self._run(argv) File "/Users/timeless/.vitualenvs/mywork/lib/python2.7/site-packages/flake8/main/application.py", line 383, in _run self.initialize(argv) File "/Users/timeless/.vitualenvs/mywork/lib/python2.7/site-packages/flake8/main/application.py", line 365, in initialize self.find_plugins() File "/Users/timeless/.vitualenvs/mywork/lib/python2.7/site-packages/flake8/main/application.py", line 191, in find_plugins self.check_plugins.load_plugins() File "/Users/timeless/.vitualenvs/mywork/lib/python2.7/site-packages/flake8/plugins/manager.py", line 423, in load_plugins plugins = list(self.manager.map(load_plugin)) File "/Users/timeless/.vitualenvs/mywork/lib/python2.7/site-packages/flake8/plugins/manager.py", line 311, in map yield func(self.plugins[name], *args, **kwargs) File "/Users/timeless/.vitualenvs/mywork/lib/python2.7/site-packages/flake8/plugins/manager.py", line 421, in load_plugin return plugin.load_plugin() File "/Users/timeless/.vitualenvs/mywork/lib/python2.7/site-packages/flake8/plugins/manager.py", line 186, in load_plugin raise failed_to_load flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "SC" due to invalid syntax (__init__.py, line 153).

Can you help me solve this problem?
Thank you!

Empty comment causes exception

Running this plugin on code with comments that are just # noqa gives me:

  File "/usr/local/lib/python3.8/site-packages/flake8_spellcheck/__init__.py", line 170, in _parse_token
    and token_info.string.lstrip("#").split()[0] != "noqa:"
IndexError: list index out of range

Inclusive renaming for --whitelist and whitelist.txt

As the spellcheck "whitelist.txt" file is generally a dictionary of allowed terminology within the codebase, could allowdict.txt, allowterm.txt or allowlist.txt be used instead of whitelist naming?

For non-breaking changes, whitelist.txt could remain as a backwards-compatible default and be used in the code but not in the documentation. A double-default would be required to fall back to the older version. Terminology used within the project documentation could be the renamed file.

If this is something the projects authors are interested in I could take a crack at making this change.

In either case, as an improvement to the documentation, the readme could note the way to change the default whitelist.txt file using --whitelist parameters.

generate text file with all unkown words

Thank you very much for this great plugin.
it would be great to have an option to dump all the unknown words to a single text file that can then be edited to update the whitelist file

Release new version for 0.25.0

I am trying to use the pandas.txt dictionary but I just realised that it hasn't been released yet to PyPI. Can we get a new release for this please?

Segmentation error in comments

First of all, I like the plug-ins you developed.
But I found:

SC100 Possibly misspelt word: ''attempts''
SC100 Possibly misspelt word: 'login''
SC100 Possibly misspelt word: '

The reason for these results is that I temporarily commented out some normal Python statements.
Just like:

logger.debug('Incrementing login attempts', extra={'data': {'email': email, 'ip_address': ip_address}})

Could you fix this bug?
Thank you!

Pre-commit addition is heavy

I tried to update to the new main this morning.
poetry run pre-commit install --install-hooks fails for me

[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('go', 'install', './...')
return code: 1
expected return code: 0
stdout:
    Executable `go` not found

Why do I need go? What is that giving the project that is helpful?

Recognise Python's magic methods

Python code which defines "magic methods" (a.k.a. "dunder methods") can lead to a lot of errors from flake8-spellcheck

For example, each of the following methods will raise errors, because eq, gt, radd, etc are not valid English words

class Fred:
    def __eq__(self, other): pass
    def __gt__(self, other): pass
    def __radd__(self, other): pass
    def __aiter__(self, other): pass
    def __matmul__(self, other): pass
    def __instancecheck__(self, other): pass

Ignore punctuation?

Is there a way to ignore punctuation?

If I have a line in a python file like this:

# Tip: Can run try it out using: 'pyinfra @docker/python python.py'

It complains about these:

./examples/python.py:3:1: SC100 Possibly misspelt word: ''pyinfra'
./examples/python.py:3:8: SC100 Possibly misspelt word: 'py''

Note the trailing quote on each.

Allow whitelist in pyproject.toml

Would it be possible to support adding the whitelist as a configuration option inside pyproject.toml as an alternative to the whitelist.txt file?

I don't want to adopt this plugin if it means increasing the amount of config files in my project.

add possibility to specify white list addition within python files

Hello
thank you for this great package. It sometimes feels not very convenient to add all word in a single whitelist file and
we may want to ignore some world only in some files.
It would be great if we could specify a per-file whitelist as well through a comment in each python file
similarly, to the "ignore" option in the cSpell visual studio plugin

Whitelist names from the standard lib?

Hi, thank you so much for this plugin, I'm looking forward to have only existing words as names inside the code (and have an automatic way of forbidding abbreviations).

Currently however, it is nearly impossible to properly use it, at it throws errors at many of the standard library or third party names, e.g. pathlib, joinpath, asdict not mentioning names defined in packages such as numpy, opencv, pillow.

Would there be a way to spellcheck only variables defined in the module to check? Or at least provide a way to whitelist the complete standard library...

Thanks in advance!

Don't check noqa comments

The comment # noqa: followed by a Flake8 error is used for ignoring a specific error on a specific line. Comments beginning with # noqa: should be ignored so I don't have to add every noqa pragma by hand to my allow list.

the code for ignoring noqa still has issues

while fighting with mypy, i discovered that the idiomatic way to disable mypy and flake8 for a line is # type: ignore # noqa: SC100, which causes an issue since the comment only recognizes comments that start with "noqa:"

IndexError caused by lines containing only "#" characters

Hi Michael,

I've found that an IndexError exception is raised, at line 173 of the flake8_spellcheck/__init__.py file, whenever a commend consisting only of "#" characters is found (e.g., "#######"). This issue is similar to issue #34.

I replaced line 171 with

and token_info.string.lstrip("#").strip() != ''

and it seems to have solved this issue while being compatible with your solution to #34.

I'll submit a merge request soon so you can test it further and see if it can be included in some future release.

Cheers,
Paulo.

Words that have numbers on the end fail.

I have a similar issue to #61 which currently makes the plugin unusable. The below happens despite using all of the dictionaries.

data.py:28:41: SC200 Possibly misspelt word: 'dict1'
data.py:58:36: SC200 Possibly misspelt word: 'file1'

An approach that notices the trailing numbers, checks if the word is valid and then allows the whole word to pass seems straight forward and unlikely to introduce failures. xyz1 is not a valid word. file1 clear is "file one".

I am happy to post a PR if that approach is acceptable.

I am using 0.25.0 installed from pypi.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.