1.0.1 • Published 4 years ago

tidyscript v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

TidyScript Build Status codecov

A CLI tool that analyses your TypeScript of JavaScript code, checking for basic impediments to readability. The tool can be configured via a YAML config that sets limits on the length, in lines, of certain code block types, like functions, loops and classes. You can also set limits on the total number of occurences of these types in a given file. This is useful for reducing the number of conditionals in your code or reducing the number of functions in a class. Files that may have different structure to the rest of your project can be ignored. The data is then displayed in table form in the terminal, using Taybl.

Installation

To install TidyScript run

npm i tidyscript

Usage

To analyze your code using TidyScript, add it as a script to your package.json as

"tidyscript": tidyscript

and then run the command

npm run tidyscript <path>

where <path> is the directory or file that you want to analyze. Glob patterns can also be used. This will run TidyScript using some default values.

Installing TidyScript globally means you can just run

tidyscript <path>

from the root of any project.

To customise the limits you want to impose, and ignore any extraneous files, you'll need a .tidyscript.yml config file. A config file can be generated by running

tidyscript init

at the root of your project. Then values can be added for specific block types based on number of lines or number of occurences in any given file.

All blocks that violate these rules are then tabulated and displayed in the terminal.

Configuration

Line Limits

Line limits are limits on the number of lines in a given block type. That is, if a limit of 6 is specified for the 'function' type, then all functions with more than 6 lines in their body will be reported on. This is useful because functions, loops, if-statements and pretty much any block type becomes increasingly difficult to understand as the number of lines increases.

Type Limits

Type limits are limits on the number of occurences of a certain block type in a given file. That is, if a limit of 1 is specified for the 'class' type, then all files containing more than 1 class will be reported on. This is useful because code can often become worse with high concentrations of if-statements or loops. Also, for example, declaring multiple classes in the same file can sometimes be useful, but, more often than not, confuses the intention of the code.

Ignore

Some files have a purpose entirely different to the rest of the code, and thus don't abide by traditional ideas of cleanliness. It therefore makes more sense to ignore these files, rather than analyze them. To ignore a file or directory, add it to the list of files to ignore in the tidyscript config. Remember to seperate these paths into a list by using hyphens. Glob patterns are allowed in the ignore list, however, depending on the number of files matching the glob, this could impact performance. It is best to just ignore individual files and directories where possible.

Contributing

All contributions to TidyScript are welcome! Bug reports and feature requests are also encouraged. New functionality should be tested, and all existing tests should pass too. No one will be mad at you if you get it wrong so feel free to get involved!

Thanks for using TidyScript!