Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
@attilagyongyosi/path-linter
Advanced tools
Lightweight, zero-dependency library to lint file paths in a project.
Consistency is always the best teacher
Well, my therapist says that I'm a bit too keen on static analysis. I can't really help it though, so recently, I started to look for a way to enforce a file naming convention for a big software project.
The NPM registry is not overly saturated with solutions to this problem, and the ones I found left me hungry for more. Some way or the other, there was always something bothering me.
For a while, I also wanted to do some open source project on my own, just for the sake
of trying myself in this game.
So here it is!
It is currently ~7kb in size, comes with no dependencies. The size could be smaller, I sacrificed it a bit on the altar of structural well-being.
Enjoy!
path-linter
should be added as a devDependency
:
npm install --save-dev @attilagyongyosi/path-linter
or
yarn add --dev @attilagyongyosi/path-linter
path-linter
needs a JSON configuration file somewhere in your project where you specify
your linting rules.
You can specify different linting rules for different directories in your project.
Rules can either be a regular expression or one of the built-in naming conventions that
path-linter
supports out of the box.
Place a file named path-linter.json
, .path-linter.json
or .pathlinterrc
in your project root
and path-linter
will detect them automatically.
If your configuration is placed elsewhere or named otherwise, you can specify
it with the --config <config-file-path>
CLI switch. See 5. Usage.
path-linter
supports the following naming conventions, so you don't need to configure a
regular expression for them:
kebab-case
You can configure linting severity in the top-level severity
configuration property.
It is error
by default which will fail the linting process when file path do not adhere
to configured conventions, or can be warning
to just log warnings on failing files.
There are situations where you want to skip certain parts of a file path and not have them linted.
One common example would be when you want your paths to adhere to kebab-case
naming but you
also use Jest for testing. Jest mocks need to be in a directory called __mocks__
which break
the linting rule.
To accommodate this situation, you can specify an ignore
property for a linting rule config.
This property should be an array of strings and path-linter
will ignore these substrings in file paths.
{
"colorize": true,
"severity": "warning",
"rules": [{
"directory": "src",
"rule": "kebab-case",
"ignore": [ "__tests__", "__mocks__" ]
}, {
"directory": "tests",
"rule": ".*\\.spec\\.ts"
}]
}
You can also find an example in sample-config.json.
Wire it into your NPM scripts in package.json
.
For example:
{
"scripts": {
"lint:paths": "path-linter --config some-config.json --colorize"
}
}
Then you can execute it with
npm run lint:paths
or
yarn lint:paths
--config <path>
Specifies the relative path to a configuration file. If not specified, the library will try to look up a
path-linter.json
file in the project root.
--colorize
Enables colorization for the console output.
This can also be set in the configuration file's colorize
property.
Feel free to open issues or pull requests if you have some improvement on the library. I'm open to everything!
This project is licensed under the MIT License - see the LICENSE.md file for details
camelCase
, dot.notation
and snake_case
FAQs
Linter for consistent directory and file naming.
The npm package @attilagyongyosi/path-linter receives a total of 5,027 weekly downloads. As such, @attilagyongyosi/path-linter popularity was classified as popular.
We found that @attilagyongyosi/path-linter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.