2.1.1 • Published 6 months ago

@exlint.io/inflint v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Inflint is a tool which scans and verifies files and folders name conventions.

Inflint allows you to easily set file names convention in your repository.

Demo

Inflint

Installation

Globally

npm install --global @exlint.io/inflint

Locally

npm install --save-dev @exlint.io/inflint

Usage

$ inflint [options] [files]

ESM support

Inflint now supports only ESM modules, from version >1.2.10. For any issue regarding this, please visit this link https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

Configuration

You can specify the configuration of Inflint through various options. Configuration can be set in the following files:

  • a package.json property: "inflint": {...}
  • a .inflintrc file in JSON or YAML format
  • a .inflintrc.json, .inflintrc.yaml, .inflintrc.yml, .inflintrc.js, .inflintrc.ts, or .inflintrc.cjs file
  • a inflint.config.ts, inflint.config.js, or inflint.config.cjs CommonJS module exporting an object

Rules format

When applying rules either via the CLI or other configuration, you must follow the rules format. "1" and "warn" are warnings rules, "2" and "error" are errors rules. Each rule has key and value. The key represents the glob pattern. When a file matches the pattern, it will be enforced by the rule. The rule value represents the rule enforcement.

Rules enforcement format:

  • Set rules of files-existence: 1 | 2 | 'warn' | 'error' | [1] | [2] | ['warn'] | ['error']

    Example: { './src/**/*': 2 } Inflint emits an error if there are any files/folders inside "src" folder

  • Set rules to match file names conventions: [1, <convention>] | [2, <convention>] | ['warn', <convention>]| ['error', <convention>]

    Example: { './src/**/*': [1, 'kebab-case'] } Inflint emits an error if there are any files/folder which do not match the "kebab-case" convention name inside "src" folder.

  • Set rules options: [1, <convention>(optional), <options>] | [2, <convention>(optional), <options>] | ['warn', <convention>(optional), <options>] | ['error', <convention>(optional), <options>]

    Example1: { './src/**/*': [1, { onlyFiles: true }] } Inflint emits an error if there are any files inside "src" folder (and allows folders to exist)

    Example2: { './src/**/*': [1, 'point.case', { onlyFiles: true }] } Inflint emits an error if there are any files which do not match the "point-case" convention name inside "src" folder (and allows folders inside "src" folder not to match the "point.case" pattern)

If you provide unknown convention which isn't known one or a configured alias, Inflint considers the "convention" as regex.

Rule option

You can set options for any rule, in order to get some customization.

  • onlyDirectories: Boolean (default: false)

    Inflint checks the rule with directories only, skips files.

  • onlyFiles: Boolean (default: false)

    Inflint checks the rule with files only, skips directories.

  • dot: Boolean (default: true)

    Allow Inflint to match files and directories starting with a period (.).

  • caseSensitiveMatch: Boolean (default: true)

    Enables a case-sensitive mode for matching files and folders.

File names conventions

You can set file names conventions rules using known ones. Inflint allows you to set the following: | Convention | Alias | Description | | :------------------------- | :--------------------------- | :------------------------------------------------------------------------------------------------ | | lowercase | lowercase | Every letter must be lowercase. Ignores non-letters | | camelcase | camelCase | Must be in "camelCase" format. Only letters and digits are allowed | | camelcase-point | camelCase.point | Must be in "camelCase" format. Only letters, digits and . are allowed | | pascalcase | PascalCase | Must be in "PascalCase" format. Only letters and digits are allowed | | pascalcase-point | PascalCase.Point | Must be in "PascalCase" format. Only letters, digits and . are allowed | | snakecase | snake_case | Must be in "snakecase" format. Only lowercase letters, digits and `are allowed | | snakecase-point |snakecase.point| Must be in "snake_case" format. Only lowercase letters, digits,and.are allowed | | screamingsnakecase |SCREAMINGSNAKE_CASE| Must be in "SCREAMING_SNAKE_CASE" format. Only uppercase letters, digits andare allowed | | screamingsnakecase-point |SCREAMINGSNAKE_CASE.POINT| Must be in "SCREAMING_SNAKE_CASE" format. Only uppercase letters, digits,and.are allowed | | kebabcase |kebab-case| Must be in "kebab-case" format. Only lowercase letters, digits and-are allowed | | kebabcase-point |kebab-case.point| Must be in "kebab-case" format. Only lowercase letters, digits,-and.are allowed | | pointcase |point.case| Must be in "point.case" format. Only lowercase letters, digits and.` are allowed |

CLI Rules

When adding rules via the CLI, you need to provide a valid JSON for the --rule argument. You can provide multiple rules. The JSON should follow the rules format described above.

Example: inflint --rule "{ \"src/**/*\": [1] }"

Aliases

You can use the known conventions, or you can add your own by applying aliases, via the CLI or other configuration. To use the aliases, simply use the alias name as you would use a known convention. Aliases should be applied with the following format:

  • <alias_name>: <regex> Inflint will apply the alias name to match the provided regex.

    Example: Applying the alias { myAlias: '^.*$' } and the rule { 'src/**/*': [2, 'myAlias'] } Inflint checks any file/folder in "src" folder to match the alias regex.

  • <alias_name>: [<regex>, <regex_flags>] Inflint applies the alias name to match the provided regex with given regex flags.

    Example: { myAlias: ['^.*$', 'i'] } Any rule applied with myAlias alias tries to match files/folders names by the provided regex and the i regex flag.

CLI Aliases

When adding aliases via the CLI, you need to provide a valid JSON for the --alias argument. You can provide multiple aliases. The JSON should follow the aliases format described above.

Example: inflint --alias "{ \"myAlias\": \"^\\.\" }"

You can escape aliases regex with in the CLI if you prefix character with \\. "^\\." will match any string begins with dot (.)

CLIConfiguration keyTypedefaultDescription
-extendsString-A path to configuration file to extend configurations from
--no-inflintrc-BooleanfalseWhether Inflint ignores any configuration file
-c, --config-String-The path to a configuration file which will be used by Inflint
--rulerulesAbove-Inflint rules to use against files
--aliasaliasesAbove-Inflint aliases to use together with rules
--ignore-pathignorePathString.inflintignoreIgnore file path Inflint will use to ignore patterns
--no-ignoreignoreBooleanfalseDisable use of ignore files and patterns
--ignore-patternignorePatternsString[][]Patterns of files to ignore (in addition to those in .inflintignore)
--quietquietBooleanfalseWhether to report errors only
--max-warningsmaxWarningsNumber0Number of warnings to trigger non-zero exit code
--bailbailBoolean or Number0Number of failures (errors) to make Inflint to exit. Setting "bail" to true is the same as setting "1"
-o, --output-fileoutputFileString-Specify file to write report to
--color, --no-color-BooleantrueForce enabling/disabling of color
-h, --help-BooleanfalseShow help
-v, --version-BooleanfalseOutput the version number
--env-info-BooleanfalseOutput the environment version

Examples

Support

For support, email talrofe111@gmail.com or open an issue at inflint issues.

Contributing

Contributions are always welcome!

See CONTRIBUTING.md for ways to get started.

Please adhere to this project's CODE_OF_CONDUCT.md.

Authors

License

MIT