Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 00ab077

Browse files
committed
Initial commit of shared Socket ESLint config
0 parents  commit 00ab077

14 files changed

+4100
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
indent_style = space
7+
indent_size = 2
8+
charset = utf-8
9+
trim_trailing_whitespace = true

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig-less",
3+
"root": true
4+
}

.github/workflows/npm-test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- '*'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
test:
18+
name: Node ${{ matrix.node_version }} on ${{ matrix.os }}
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
node_version: [lts/*]
24+
os: [ubuntu-latest]
25+
steps:
26+
- uses: actions/checkout@v3
27+
- name: Use Node.js ${{ matrix.node_version }}
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: ${{ matrix.node_version }}
31+
cache: 'npm'
32+
- run: npm ci
33+
- run: npm test

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Basic ones
2+
/node_modules
3+
/yarn.lock
4+
/.vscode
5+
6+
# Library specific ones

.husky/pre-push

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm test

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Socket Inc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Socket ESLint Config
2+
3+
For projects with a `tsconfig.json`:
4+
5+
```json
6+
{
7+
"extends": "@socketsecurity",
8+
"root": true,
9+
"parserOptions": {
10+
"project": "./tsconfig.json"
11+
}
12+
}
13+
```
14+
15+
For projects without a `tsconfig.json`:
16+
17+
```json
18+
{
19+
"extends": "@socketsecurity/eslint-config/tsconfig-less",
20+
"root": true
21+
}
22+
```

index.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
'use strict'
2+
3+
module.exports = {
4+
'root': true,
5+
'env': {
6+
'es2021': true,
7+
'node': true
8+
},
9+
'parser': '@typescript-eslint/parser',
10+
'parserOptions': {
11+
'ecmaVersion': 'latest',
12+
'jsx': true,
13+
'sourceType': 'module'
14+
},
15+
'plugins': [
16+
'@typescript-eslint',
17+
'react-hooks'
18+
],
19+
'extends': [
20+
'./lib/standard-eslint-ts',
21+
'plugin:import/recommended',
22+
'plugin:import/typescript'
23+
],
24+
'settings': {
25+
'import/resolver': {
26+
'typescript': true,
27+
'node': true
28+
}
29+
},
30+
'overrides': [
31+
{
32+
'files': ['*.ts', '*.tsx'],
33+
'rules': {
34+
'no-undef': 'off'
35+
}
36+
},
37+
{
38+
'files': ['*.jsx', '*.tsx'],
39+
'rules': {
40+
'@typescript-eslint/consistent-type-imports': 'off'
41+
}
42+
}
43+
],
44+
'rules': {
45+
'camelcase': 'off',
46+
'multiline-ternary': 'off',
47+
'no-labels': 'off',
48+
'no-useless-return': 'off',
49+
'no-void': 'off',
50+
'quote-props': 'off',
51+
'react/jsx-indent': 'warn',
52+
'@typescript-eslint/indent': 'off',
53+
'@typescript-eslint/no-extra-parens': 'off',
54+
'@typescript-eslint/quotes': 'off',
55+
'@typescript-eslint/comma-dangle': ['warn', {
56+
'arrays': 'ignore',
57+
'enums': 'ignore',
58+
'exports': 'ignore',
59+
'functions': 'never',
60+
'generics': 'ignore',
61+
'imports': 'ignore',
62+
'objects': 'ignore',
63+
'tuples': 'ignore'
64+
}],
65+
66+
'spaced-comment': 'off',
67+
68+
'react-hooks/rules-of-hooks': 'off',
69+
'react-hooks/exhaustive-deps': 'off',
70+
71+
'@typescript-eslint/consistent-type-imports': [
72+
'error',
73+
{ 'prefer': 'type-imports', 'disallowTypeAnnotations': true }
74+
],
75+
'import/no-named-as-default': 0,
76+
'import/no-named-as-default-member': 0,
77+
'import/order': [
78+
'warn',
79+
{
80+
'groups': ['builtin', 'external', ['internal', 'parent', 'sibling', 'index'], 'type'],
81+
'pathGroups': [
82+
{
83+
'pattern': 'react',
84+
'group': 'builtin',
85+
'position': 'before'
86+
}
87+
],
88+
'pathGroupsExcludedImportTypes': ['react'],
89+
'newlines-between': 'always',
90+
'alphabetize': {
91+
'order': 'asc'
92+
}
93+
}
94+
]
95+
}
96+
}

lib/standard-eslint-ts.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Use to generate an up to date @typescript-eslint adapted standardjs,
2+
// which makes use of all extended rules https://typescript-eslint.io/rules/#extension-rules
3+
// Similar to https://github.com/typescript-eslint/typescript-eslint/blob/f4016c24f9023e8a42def9501b68c4a908cbfede/packages/eslint-plugin/src/configs/recommended.ts
4+
5+
const { rules } = require('@typescript-eslint/eslint-plugin')
6+
const standard = require('eslint-config-standard')
7+
8+
const neededChanges = {}
9+
const newChanges = {}
10+
11+
for (const ruleId in rules) {
12+
const ruleDefinition = rules[ruleId]
13+
if (ruleDefinition.meta.docs.extendsBaseRule) {
14+
if (standard.rules[ruleId]) {
15+
neededChanges[ruleId] = 'off'
16+
if (ruleId !== 'dot-notation') {
17+
newChanges['@typescript-eslint/' + ruleId] = standard.rules[ruleId]
18+
}
19+
}
20+
}
21+
}
22+
23+
const config = {
24+
extends: ['standard', 'standard-jsx'],
25+
rules: {
26+
...neededChanges,
27+
...newChanges
28+
}
29+
}
30+
31+
module.exports = config

0 commit comments

Comments
 (0)