Skip to content

Commit

Permalink
Refactored JS and Svelte linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ascartabelli committed Sep 7, 2023
1 parent e82cfc4 commit 716f7a4
Show file tree
Hide file tree
Showing 18 changed files with 4,559 additions and 3,498 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = tab
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"./js/index.js"
],
"plugins": [],
"root": true,
"rules": {},
"settings": {}
};
31 changes: 31 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: check

on:
push:
branches: [ main ]

pull_request:

jobs:
checks:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

name: Node ${{ matrix.node-version }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Installing dev dependencies
run: npm ci

- name: Checking rules
run: npm run check-rules

- name: Linting
run: npm run lint
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# MacOS
.DS_Store

# Dependencies
node_modules

# Env files
.env
node_modules/
.env.*

# Logs
*.log
npm-debug.log*
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

574 changes: 373 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
# dusk-eslint-config
# Dusk ESLint rules

> ESLint config use by Dusk Javascript apps.
ESLint config used by [Dusk](https://dusk.network/) JavaScript apps.

## Installation

```bash
npm i -D eslint @dusk-network/eslint-config
npm i -D @dusk-network/eslint-config
```

The package requires the following peer dependencies:
- [`eslint`](https://github.com/eslint/eslint) `>=8`
- [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import) `>=2`

If you are using Svelte rules the package need the following optional dependency:

- [`eslint-plugin-svelte`](https://github.com/sveltejs/eslint-plugin-svelte) `>=2`

## Usage

```json
"eslintConfig": {
"extends": "@dusk-network"
}
Add the rulesets you want in the `extends` section of your ESLint configuration file.

e.g. to use both JS and Svelte's rules:

```javascript
// ...

extends: [
"@dusk-network/eslint-config/js",
"@dusk-network/eslint-config/svelte"
]

// ...
```

# npm scripts

- `npm run bump` updates version number using an interactive shell
- `npm run check` checks for deprecated rules and performs the linting check
- `npm run check-js` checks for deprecated JS rules
- `npm run check-rules` checks for deprecated JS and Svelte rules
- `npm run check-svelte` checks for deprecated Svelte rules
- `npm run lint` performs the linting check
23 changes: 0 additions & 23 deletions index.js

This file was deleted.

89 changes: 89 additions & 0 deletions js/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module.exports = {
rules: {
"array-callback-return": ["error", { allowImplicit: true }],
"class-methods-use-this": 0,
"complexity": ["error", 14],
"consistent-return": ["error", { "treatUndefinedAsUnspecified": false }],
"consistent-this": "error",
"curly": ["error", "all"],
"default-case": "error",
"dot-location": ["error", "property"],
"dot-notation": "error",
"eqeqeq": "error",
"func-call-spacing": ["error", "never"],
"max-depth": ["error", 3],
"max-len": ["error", {
"code": 110,
"comments": 110,
"ignorePattern": "^ \\* @overview",
"ignoreUrls": true
}],
"max-nested-callbacks": ["error", 3],
"max-params": ["error", 5],
"max-statements": ["error", 15, { "ignoreTopLevelFunctions": true }],
"max-statements-per-line": ["error", { "max": 1 }],
"new-cap": ["error", { "newIsCap": true, "properties": true }],
"no-alert": "error",
"no-array-constructor": "error",
"no-caller": "error",
"no-confusing-arrow": ["error", { "allowParens": true }],
"no-console": "error",
"no-duplicate-imports": ["error", { "includeExports": true }],
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-loop-func": "error",
"no-multi-spaces": "error",
"no-nested-ternary": 0,
"no-new": "error",
"no-new-object": "error",
"no-octal-escape": "error",
"no-param-reassign": 0,
"no-proto": "error",
"no-prototype-builtins": "error",
"no-restricted-globals": ["error", "event"],
"no-return-assign": ["error", "always"],
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error",
"no-throw-literal": "error",
"no-undef": "error",
"no-undef-init": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": "error",
"no-unused-expressions": [
"error", {
"allowShortCircuit": true,
"allowTernary": false
}
],
"no-unused-vars": [2, { "args": "after-used" }],
"no-use-before-define": [0, "nofunc"],
"no-useless-call": "error",
"no-useless-concat": "error",
"no-useless-escape": "error",
"no-var": "error",
"no-whitespace-before-property": "error",
"no-with": "error",
"prefer-const": [
"error", {
"destructuring": "any",
"ignoreReadBeforeAssign": false
}
],
"radix": "error",
"semi": ["error", "always"],
"strict": ["error", "function"],
"wrap-iife": ["error", "inside"],
"yoda": "error"
}
};
5 changes: 5 additions & 0 deletions js/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
"import/no-duplicates": 0
}
};
19 changes: 19 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const rules = [
"./base",
"./import",
"./style"
].map(require.resolve);

module.exports = {
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
...rules
],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module"
},
rules: {}
};
Loading

0 comments on commit 716f7a4

Please sign in to comment.