Coder Social home page Coder Social logo

phantypocheck's Introduction

PhanTypoCheck

Build Status Latest Stable Version License

This Phan plugin checks for typos in PHP files, with low false positives.

It checks all string literals, inline html, and doc comments (on by default). It also checks variables, element names, and element usages (using heuristics to guess individual words of camelCase or snake_case identifiers).

This also emits warnings if strings with typos are passed to calls to gettext(), _(), and ngettext().

Installing

This can be installed with composer

composer require --dev tysonandre/phantypocheck

After it is installed, add the relative path to TypoCheckPlugin.php to the plugins section of .phan/config.php, e.g.

    'plugins' => [
       // other plugins,
       'vendor/tysonandre/phantypocheck/src/TypoCheckPlugin.php',
    ],

This can also be manually downloaded (the current version doesn't have external dependencies).

Running (standalone)

This can be run as vendor/bin/phptypocheck path/to/file.php path/to/folder.

When passed a folder name, this will check for .php files within that folder, recursively.

Details

The typo checks use dictionary.txt from https://github.com/codespell-project/codespell/

  • It might be easier to just use codespell, depending on the use case.

    However, that would not tell you what type of identifier the string occurred in (and allow filtering by that).

    codespell also has issues analyzing the start/end of single quoted strings.

Options

Options can be passed in your .phan/config.php.

    'plugin_config' => [
        // can provide a path to a file with a list of typos to not warn about (case insensitive)
        // See tests/phantypocheck_ignore.txt for an example file.
        'typo_check_ignore_words_file' => 'phantypocheck_ignore.txt'

        // can be added to Phan configuration to make this skip checking comments, strings, and inline HTML for typos.
        // (will *only* check uses of gettext()/_()/ngettext())
        'typo_check_comments_and_strings' => false,
    ],

License

dictionary.txt is a derived work of English Wikipedia and is released under the Creative Commons Attribution-Share-Alike License 3.0 http://creativecommons.org/licenses/by-sa/3.0/ (according to https://github.com/codespell-project/codespell#license)


PhanTypoCheck is available under the GPL v3 License (see LICENSE)

PhanTypoCheck is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PhanTypoCheck is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PhanTypoCheck.  If not, see <https://www.gnu.org/licenses/>.

phantypocheck's People

Contributors

tysonandre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

phantypocheck's Issues

Look into using PhpToken::getAll

The performance improvement was negligible, the decrease in memory was unimportant since references to the token array weren't kept in this use case.

Runtime is quadratic when analyzing dictionary.txt

Be more efficient about computing the line number. Only bother with setting up data structures/indices needed if a typo was seen.

time ./phptypocheck data/dictionary.txt > /dev/null
./phptypocheck data/dictionary.txt > /dev/null  2.45s user 0.03s system 99% cpu 2.483 total
# remove half of the lines
time ./phptypocheck data/dictionary.txt > /dev/null
./phptypocheck data/dictionary.txt > /dev/null  0.50s user 0.03s system 99% cpu 0.533 total

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.