Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sleavely/eslint-plugin-js-rules
Opinionated rules for maintainable projects
https://github.com/sleavely/eslint-plugin-js-rules
code-quality eslint eslint-plugin javascript static-analysis
Last synced: about 1 month ago
JSON representation
Opinionated rules for maintainable projects
- Host: GitHub
- URL: https://github.com/sleavely/eslint-plugin-js-rules
- Owner: Sleavely
- Created: 2023-09-17T08:18:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-10T19:21:26.000Z (over 1 year ago)
- Last Synced: 2025-01-13T15:14:18.263Z (about 1 month ago)
- Topics: code-quality, eslint, eslint-plugin, javascript, static-analysis
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@sleavely/eslint-plugin-js-rules
- Size: 107 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @sleavely/eslint-plugin-js-rules
Opinionated rules for maintainable projects.
Typescript-specific rules is a separate plugin; [`@sleavely/eslint-plugin-ts-rules`](https://github.com/Sleavely/eslint-plugin-ts-rules)
## Installing
```sh
npm i --save-dev @sleavely/eslint-plugin-js-rules
``````js
// .eslintrc.cjs
module.exports = {
// ..
plugins: [
'@sleavely/js-rules',
],
rules: {
'@sleavely/js-rules/destructure-env': ['error', 'always'],
'@sleavely/js-rules/uppercase-env': ['error', 'always'],
}
}
```## Rules
### js-rules/destructure-env
Environment variables that affect how the application runs should be easy to find.
Setting default values that are strings will ensure that you never have to deal with "possibly undefined" cases.
```js
// ✅ Destructured and have default string values
const {
ENVIRONMENT = 'dev',
POTATO = '',
} = process.env
console.log(POTATO)// ❌ Needs destructuring
console.log(process.env.POTATO)// ❌ Needs destructuring
const { env } = process
console.log(env.POTATO)// ❌ Needs destructuring
const { env: renamedEnv } = process
console.log(env.POTATO)// ❌ Needs destructuring
const env = process.env
console.log(env.POTATO)// ❌ Needs a default string value
const { POTATO } = process.env
console.log(POTATO)
``````js
// ✅
import foo from 'foo'
const {
ENV_VAR = ''
} = process.env
export const foobar = () => foo()// ❌ Only import/require may appear prior to process.env
import foo from 'foo'
export const foobar = () => foo()
const {
ENV_VAR = ''
} = process.env// ❌ process.env must be destructured in root scope
export const logEnv () => {
const {
ENV_VAR = ''
} = process.env
console.log(ENV_VAR)
}
```### js-rules/uppercase-env
Environment variables are constants throughout your applications lifecycle. Uppercasing environment variables helps distinguish them from other identifiers.
```js
// ✅
const {
POTATO = ""
} = process.env// ✅
console.log(process.env.POTATO)// ❌
const {
potato = ""
} = process.env// ❌
console.log(process.env.potato)
```