Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
eslint-plugin-ts-ban-snippets
Advanced tools
Ban snippets of TypeScript from your project, using a custom eslint rule 'ts-ban-snippets'.
Ban snippets of TypeScript from your project, using a custom eslint rule 'ts-ban-snippets'.
examples: "return void reject", "it.only", "debugger".
This is an eslint port of tslint-ban-snippets
The rule is quite flexible and could potentially avoid having to create multiple custom eslint rules.
This plugin requires your project to use TypeScript (>=4.1.3).
yarn add eslint-plugin-ts-ban-snippets --dev
The plugin relies on TypeScript compiler services to resolve types.
The following examples show how to configure banned snippets in the .eslintrc
file(s) of your project.
note: in the .eslintrc
file, you need to set your tsconfig.json
file in your eslint configuration via parserOptions
:
{
"plugins": ["ts-ban-snippets"],
"parserOptions": {
"project": "./tsconfig.json"
}
}
.eslintrc
This example detects use of return void reject
or return void resolve
and raises an error.
{
"plugins": ["ts-ban-snippets"],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"ts-ban-snippets/ts-ban-snippets": [
"error",
{
"banned": [
{
"snippets": ["return void reject", "return void resolve"],
"message": "Please do not return void - instead place the return statement on the following line."
}
]
}
]
}
}
.eslintrc
This example also detects use of return void reject
or return void resolve
and raises an error - but using a regular expression.
{
"plugins": ["ts-ban-snippets"],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"ts-ban-snippets/ts-ban-snippets": [
"error",
{
"banned": [
{
"regexSnippets": ["return void [reject|resolve]"],
"message": "Please do not return void - instead place the return statement on the following line."
}
]
}
]
}
}
.eslintrc
with multiple banned snippetsThis example has a list of banned snippets:
return void reject
or return void resolve
it.only
or describe.only
it.skip
or test suites via describe.skip
{
"plugins": ["ts-ban-snippets"],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"ts-ban-snippets/ts-ban-snippets": [
"error",
{
"banned": [
{
"snippets": ["return void reject", "return void resolve"],
"message": "Please do not return void - instead place the return statement on the following line."
},
{
"snippets": ["it.only", "describe.only"],
"message": "Do not enable only some tests."
},
{
"snippets": ["it.skip", "describe.skip"],
"message": "Do not skip tests."
}
]
}
]
}
}
.eslintrc
with included and excluded pathsThis example has one banned snippet (return void reject
or return void resolve
).
Only files with a path that contains my-component
and does not contain excluded
are scanned.
{
"plugins": ["ts-ban-snippets"],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"ts-ban-snippets/ts-ban-snippets": [
"error",
{
"banned": [
{
"snippets": ["return void reject", "return void resolve"],
"message": "Please do not return void - instead place the return statement on the following line.",
"includePaths": ["my-component"],
"excludePaths": ["excluded"]
}
]
}
]
}
}
For working tests, please see the unit tests.
For a real code example, see the test harness. In particular, the .eslintrc file.
Original work by Sean Ryan - mr.sean.ryan(at gmail.com)
This project is licensed under the MIT License - see the LICENSE file for details
For available options and for examples, see the Rule doc:
FAQs
Ban snippets of TypeScript from your project, using a custom eslint rule 'ts-ban-snippets'.
The npm package eslint-plugin-ts-ban-snippets receives a total of 14 weekly downloads. As such, eslint-plugin-ts-ban-snippets popularity was classified as not popular.
We found that eslint-plugin-ts-ban-snippets 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
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.