Skip to content

Commit df6ffbf

Browse files
committed
Rework base JS config
1 parent d8ee713 commit df6ffbf

File tree

7 files changed

+1671
-87
lines changed

7 files changed

+1671
-87
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
.DS_Store
2+
.idea
3+
.vscode
14
node_modules

README.md

+2-14
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.
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.
+13-3
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.
+70-64
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,71 @@
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.recommendedTypeChecked,
15+
prettier,
16+
{
17+
languageOptions: {
18+
ecmaVersion: "latest",
19+
globals: {
20+
...globals.node,
21+
...globals.browser,
22+
},
23+
parserOptions: {
24+
projectService: true,
25+
},
26+
sourceType: "module",
27+
},
28+
plugins: {
29+
"@typescript-eslint": tseslint.plugin,
30+
prettier: prettierPlugin,
31+
},
32+
rules: {
33+
"@typescript-eslint/explicit-module-boundary-types": "off",
34+
"@typescript-eslint/no-unused-vars": [
35+
"error",
36+
{
37+
ignoreRestSiblings: true,
38+
varsIgnorePattern: "^_",
39+
argsIgnorePattern: "^_",
40+
caughtErrorsIgnorePattern: "^_",
41+
},
42+
],
43+
"@typescript-eslint/no-explicit-any": "error",
44+
"@typescript-eslint/no-empty-interface": [
45+
"error",
46+
{
47+
allowSingleExtends: true,
48+
},
49+
],
50+
"@typescript-eslint/no-use-before-define": ["error"],
51+
"no-param-reassign": [
52+
// Allow modifying props, esp. for DOM Nodes
53+
"error",
54+
{
55+
props: false,
56+
},
57+
],
58+
"prettier/prettier": "error",
6359
},
64-
}],
65-
};
60+
overrides: [
61+
{
62+
// enable the rule specifically for TypeScript files
63+
files: ["*.ts", "*.tsx"],
64+
rules: {
65+
"@typescript-eslint/explicit-module-boundary-types": ["error"],
66+
},
67+
},
68+
],
69+
},
70+
);
71+
export default config;

0 commit comments

Comments
 (0)