Skip to content

Commit 9ef933c

Browse files
authored
Merge pull request #8 from forumone/update-eslint-settings
Create shareable ESLint config
2 parents d8ee713 + 21c7442 commit 9ef933c

File tree

11 files changed

+4618
-87
lines changed

11 files changed

+4618
-87
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
.DS_Store
2+
.idea
3+
.vscode
14
node_modules

README.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
Forum One JavaScript Coding Style
1+
Forum One JavaScript Tools
22
================================
3-
4-
Our coding conventions are minor modifications of [Airbnb's legacy ES5 configuration](https://github.com/airbnb/javascript/tree/es5-deprecated/es5), with customizations for specific environments.
5-
6-
Usage
7-
-----
8-
9-
1. First, you'll need ESLint. Here's a [quick start guide](http://eslint.org/docs/user-guide/getting-started).
10-
2. For bonus points, get your [editor integrated](http://eslint.org/docs/user-guide/integrations).
11-
3. Since we're extending another config, you'll need to read the installation instructions for [`airbnb-base/legacy`](https://www.npmjs.com/package/eslint-config-airbnb-base#eslint-config-airbnb-baselegacy).
12-
4. Run `npm install eslint-config-forumone-es5`.
13-
5. Add `extends: 'forumone-es5'` to your ESLint configuration file.
14-
153
Modules
164
-------
175

186
### eslint-config-forumone-es5
197

20-
Forum One's base ES5 ESLint configuration.
8+
Forum One's base JavaScript ESLint configuration.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
## 3.0.0
4+
**Breaking Changes**: Basically everything. Requires ESLint 9 and switches to
5+
eslint:recommended as the base config. You probably aren't using version 2, but
6+
if you are, this amounts to a new start.
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
Forum One JavaScript Coding Style (ES5 Edition)
2-
----------------------------------------------
1+
Forum One JavaScript Coding Style
2+
================================
33

4-
See [forumone/javascript](https://github.com/forumone/javascript) on GitHub for a longer intro.
4+
Our JavaScript code style conventions are based on:
5+
- [ESLint's Recommended Config](https://eslint.org/docs/latest/rules/)
6+
- [TypeScript ESLint](https://typescript-eslint.io/)
7+
- [Prettier](https://prettier.io/docs/related-projects#eslint-integrations)
8+
- [Prettier Plugin: Organize Imports](https://github.com/simonhaenisch/prettier-plugin-organize-imports)
9+
with customizations for specific environments and team practices.
10+
11+
Usage
12+
-----
13+
1. Run `npm install eslint-config-forumone-es5`.
14+
2. Add `extends: 'forumone-es5'` to your ESLint configuration file.
Lines changed: 93 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,94 @@
1-
/* eslint-env node, commonjs */
2-
3-
exports.ecmaFeatures = {
4-
impliedStrict: true,
5-
};
6-
7-
// Our ES5 projects are exclusively browser-focused
8-
exports.env = {
9-
browser: true,
10-
node: false,
11-
commonjs: false,
12-
};
13-
14-
exports.extends = 'airbnb-base/legacy';
15-
16-
exports.rules = {
17-
// Overrides of airbnb-base/legacy
18-
19-
// IE8 is dead, we can require trailing commas safely
20-
'comma-dangle': ['error', 'always-multiline'],
21-
22-
// block-scoped-var and no-use-before-define cover the use cases here
23-
// no need to manually hoist as well
24-
'vars-on-top': ['off'],
25-
26-
// Style guidance left to the programmer
27-
'no-else-return': ['off'],
28-
'func-names': ['off'],
29-
30-
// Function hoisting is always safe
31-
'no-use-before-define': ['error', {
32-
functions: false,
33-
}],
34-
35-
// Allow conditionals in loops (but only if you promise that you know what you're doing)
36-
'no-cond-assign': ['error', 'except-parens'],
37-
38-
// Unconditionally require curly braces
39-
curly: ['error', 'all'],
40-
41-
// Additional rules
42-
43-
// Don't leak globals
44-
'no-implicit-globals': 'error',
45-
46-
// Disallow superfluous parentheses, unless you need to disambiguate precedence
47-
'no-extra-parens': ['error', 'all', {
48-
conditionalAssign: false,
49-
nestedBinaryExpressions: false,
50-
}],
51-
52-
// Eventually, this will be an error (and also require parameter descriptions)
53-
'valid-jsdoc': ['warn', {
54-
requireReturn: false,
55-
requireParamDescription: false,
56-
requireReturnDescription: false,
57-
58-
prefer: {
59-
arg: 'param',
60-
argument: 'param',
61-
62-
returns: 'return',
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import tseslint from "typescript-eslint";
5+
import prettier from "eslint-config-prettier";
6+
import prettierPlugin from "eslint-plugin-prettier";
7+
import globals from "globals";
8+
9+
/**
10+
* @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigFile}
11+
*/
12+
const config = tseslint.config(
13+
eslint.configs.recommended,
14+
tseslint.configs.recommended,
15+
prettier,
16+
{
17+
languageOptions: {
18+
ecmaVersion: "latest",
19+
globals: {
20+
...globals.node,
21+
...globals.browser,
22+
},
23+
sourceType: "module",
24+
},
25+
plugins: {
26+
"@typescript-eslint": tseslint.plugin,
27+
prettier: prettierPlugin,
28+
},
29+
rules: {
30+
"@typescript-eslint/explicit-module-boundary-types": "off",
31+
"@typescript-eslint/no-unused-vars": [
32+
"error",
33+
{
34+
ignoreRestSiblings: true,
35+
varsIgnorePattern: "^_",
36+
argsIgnorePattern: "^_",
37+
caughtErrorsIgnorePattern: "^_",
38+
},
39+
],
40+
"@typescript-eslint/no-explicit-any": "error",
41+
"@typescript-eslint/no-empty-interface": [
42+
"error",
43+
{
44+
allowSingleExtends: true,
45+
},
46+
],
47+
"@typescript-eslint/no-use-before-define": "error",
48+
eqeqeq: "error",
49+
"no-console": [
50+
"error",
51+
{
52+
allow: ["warn", "error"],
53+
},
54+
],
55+
"no-duplicate-imports": "error",
56+
"no-lonely-if": "error",
57+
"no-param-reassign": [
58+
// Allow modifying props, esp. for DOM Nodes
59+
"error",
60+
{
61+
props: false,
62+
},
63+
],
64+
"no-shadow": "error",
65+
"no-useless-assignment": "error",
66+
"no-var": "error",
67+
"object-shorthand": ["error", "always"],
68+
"prefer-const": "error",
69+
"prefer-destructuring": [
70+
"error",
71+
{
72+
array: false,
73+
object: true,
74+
},
75+
],
76+
"prefer-spread": "error",
77+
"prettier/prettier": "error",
78+
},
79+
},
80+
// TypeScript-specific additions
81+
{
82+
files: ["*.ts", "*.tsx"],
83+
extends: [tseslint.configs.recommendedTypeChecked],
84+
languageOptions: {
85+
parserOptions: {
86+
projectService: true,
87+
},
88+
},
89+
rules: {
90+
"@typescript-eslint/explicit-module-boundary-types": ["error"],
6391
},
64-
}],
65-
};
92+
},
93+
);
94+
export default config;

0 commit comments

Comments
 (0)