
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
naming-rules
Advanced tools
A utility to check paths and files against a naming rules file (`.namingrc.json`)
This project provides a command-line interface (CLI) for scanning files and directories to ensure they adhere to specified naming conventions. It helps identify naming rule violations based on configurable rules.
To install globally from npm:
npm install -g naming-rules
To install for local development, clone the repository and run:
npm install
After global installation, you can use the CLI directly:
naming-rules <path> [options]
For local development, you can use npm scripts:
npm run cli -- <path> [options]
-r, --reporter <reporter>
: Specify how to display the results. Options: simple
(table format) or json
(default: simple).-s, --severity <severity>
: Choose which severity levels to display. Options: 1
(Error), 2
(Warning), 3
(Information), 4
(Hint), or all
(default: all).-c, --config <config>
: Provide the path to the configuration file (default: ./naming-rules.json).To scan a directory for naming rule violations:
# Using global installation
naming-rules ./path/to/scan
# Using local development
npm run cli -- ./path/to/scan
# With options
naming-rules ./path/to/scan --reporter json --severity 1 --config ./my-config.json
The project uses a configuration file to define the naming rules. By default, it looks for ./naming-rules.json
in the current directory, but you can specify a custom path using the -c
option. The configuration file (typically named .namingrc.json
or naming-rules.json
) allows you to specify rules for file naming conventions, folder naming conventions, and content validation.
{
"rules": [
{
"type": "extension_not_allowed",
"includes": "webroot/**/*.php",
"severity": 1,
"message": "Extension [*.php] Not allowed under webroot/ because PHP sucks",
"href": "https://markdrew.io/docs/why_no_php_in_webroot.html"
},
]
}
The CLI will output diagnostics in either a simple table format or as JSON, depending on the specified reporter option. Each diagnostic message includes details such as the severity, URI, and a description of the violation.
In the .namingrc.json file you can define your own rules. The rules are defined as an array of rule objects in JSON.
Each rule object needs the following properties:
type
: The type of rule. We support the following types:
extension_not_allowed
: Disallow files with a specific extension. For example, disallowing .php
files in the webroot
folder.folder_not_allowed
: Disallow folders within the includes, for example, putting tests
in the webroot folder.filename_postfix
: Require files with a specific postfix (or suffix). For example, all js
files in the test folder should end with test.js
. Requires a value
property.regex
: Find content in files that matches the regex. Good for security checking, making sure passwords for example are not in code etc. Requires a value
property and optionally a flags
property.tag
: Find tags in the content of a file. For example make sure that we are not using the marquee
tag in our code!function
: Find functions in the content of a file. For example make sure that we are not using the eval
function in our code.includes
: A glob pattern that defines the files or folders that the rule applies to. For example webroot/**/*.php
would apply the rule to all PHP files under the webroot folder. These are based on the globbing library minimatch.
severity
: The severity of the rule. These are:
1
- Error2
- Warning3
- Information4
- Hintmessage
: The message to display when the rule is violated
href
: A URL to a page that explains the rule in more detailexcludes
: A glob pattern that defines the files or folders that the rule does not apply to. For example webroot/**/readme.md
would not match files if you have includes
of webroot/**/*.md
but you want to exclude readme.md
files. These are based on the globbing library minimatch.value
: Required for filename_postfix
and regex
rule types. For filename_postfix
, this is the required postfix/suffix. For regex
, this is the regular expression pattern.flags
: Optional for regex
rule types. Specifies regex flags (e.g., "i" for case-insensitive matching). {
"type": "extension_not_allowed",
"includes": "webroot/**/*.md",
"severity": 1,
"message": "Extension [*.md] Not allowed under webroot/ as it can show sensitive information.",
"href": "https://example.com/docs/no-markdown-in-webroot.html"
},
This rule prevents markdown files (files ending with .md
) from residing anywhere within the webroot
directory. Markdown files in this location may unintentionally expose sensitive documentation or configuration details.
{
"type": "tag",
"includes": "webroot/**/*.html",
"severity": 1,
"message": "The <marquee> tag is not allowed in webroot HTML files.",
"href": "https://example.com/docs/no-marquee-tag.html"
}
This rule prevents the use of the <marquee>
tag in HTML files within the webroot
directory. The <marquee>
tag is considered a deprecated and non-standard HTML element that should not be used in modern web development.
{
"type": "function",
"includes": "webroot/**/*.js",
"severity": 1,
"message": "The eval() function is not allowed in webroot JavaScript files.",
"href": "https://example.com/docs/no-eval-function.html"
}
This rule prevents the use of the eval()
function in JavaScript files within the webroot
directory. The eval()
function is considered a security risk and should be avoided in modern web development.
{
"type": "folder_not_allowed",
"includes": "webroot/**/tests",
"severity": 1,
"message": "Folder [tests] not allowed under [webroot/] as it can show sensitive information.",
"href": "https://example.com/tests-in-webroot.html"
}
This rule checks for folders that should not be there, for example tests
folders under the webroot
folder. This is because tests can expose sensitive information about your application.
{
"type": "filename_postfix",
"excludes": "DataProvider.js",
"includes": "unit_tests/**/*.js",
"value": ".test",
"severity": 3,
"message": "Unit tests should end with <SomeComponent>.test.js",
"href": "https://example.com/add-test-postfix.html"
}
The rule above looks for all files that are in the unit_tests
folder and checks if they end with .test
. So for example all javascript files like somecomponent.js
but if it doesn't have .test
at the end it will show an information message.
{
"type": "regex",
"includes": "webroot/**/*.js",
"value": "(password|passwd|pwd|secret|api[-_]?key)\s*[=:]\s*["']([^"']{8,})["']",
"flags": "i",
"severity": 1,
"message": "Do not add secrets or api passwords in your code",
"href": "https://example.com/docs/no-secrets-in-code.html"
}
The regex
type of rule allows you to put any regex in the value
field and it will check the content of the file for that regex. You can also specify regex flags using the flags
property (e.g., "i" for case-insensitive matching). This is useful for checking for security issues, for example, passwords in code.
Note: The above regex is just a simple example, you should use a more complex regex for your own code.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License.
FAQs
A utility to check paths and files against a naming rules file (`.namingrc.json`)
The npm package naming-rules receives a total of 3 weekly downloads. As such, naming-rules popularity was classified as not popular.
We found that naming-rules demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.