Skip to content

Commit e0748f2

Browse files
committed
chore: add eslint / prettier
1 parent 21d97d6 commit e0748f2

File tree

4 files changed

+375
-1
lines changed

4 files changed

+375
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,6 @@
8181
!*SHA*.asc
8282
!*SHA*.sig
8383
!*styles.css
84-
84+
!*eslint.config.js
85+
!*.prettierignore
86+
!*.prettierrc

.prettierignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.all-contributorsrc
2+
.github
3+
.gitea
4+
CONTRIBUTING
5+
CONTRIBUTING.md
6+
README
7+
README.md
8+
LICENSE
9+
node_modules
10+
coverage
11+
dist
12+
tests
13+
docs
14+
manifest.json
15+
tsconfig.json
16+
styles.css
17+
rollup.config.mjs

.prettierrc

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# --------------------------------------------------------------------------------------
2+
# Try prettier's new ternary formatting before it becomes the
3+
# default behavior.
4+
#
5+
# only in prettier v3.x
6+
#
7+
# Moves the ? in multiline ternaries to the end of the first line
8+
# instead of the start of the second, along with several related
9+
# changes.
10+
#
11+
# @default : false
12+
# @ref : https://prettier.io/docs/en/options.html
13+
# https://prettier.io/docs/en/options.html#experimental-ternaries
14+
# https://github.com/prettier/prettier/pull/13183
15+
# --------------------------------------------------------------------------------------
16+
# experimentalTernaries: false
17+
18+
# --------------------------------------------------------------------------------------
19+
# Specify the line length that the printer will wrap on.
20+
#
21+
# @default : 80
22+
# @ref : https://prettier.io/docs/en/options.html#print-width
23+
# --------------------------------------------------------------------------------------
24+
printWidth: 120
25+
26+
# --------------------------------------------------------------------------------------
27+
# Specify the number of spaces per indentation-level.
28+
#
29+
# @default : 2
30+
# @ref : https://prettier.io/docs/en/options.html#tab-width
31+
# --------------------------------------------------------------------------------------
32+
tabWidth: 4
33+
34+
# --------------------------------------------------------------------------------------
35+
# Indent lines with tabs instead of spaces.
36+
#
37+
# @default : false
38+
# @ref : https://prettier.io/docs/en/options.html#tabs
39+
# --------------------------------------------------------------------------------------
40+
useTabs: false
41+
42+
# --------------------------------------------------------------------------------------
43+
# Print semicolons at the ends of statements.
44+
#
45+
# true : Add a semicolon at the end of every statement.
46+
# false : Only add semicolons at the beginning of lines that
47+
# may introduce ASI failures.
48+
#
49+
# @default : true
50+
# @ref : https://prettier.io/docs/en/options.html#semicolons
51+
# --------------------------------------------------------------------------------------
52+
semi: false
53+
54+
# --------------------------------------------------------------------------------------
55+
# Use single quotes instead of double quotes.
56+
#
57+
# @default : false
58+
# @ref : https://prettier.io/docs/en/options.html#quotes
59+
# --------------------------------------------------------------------------------------
60+
singleQuote: true
61+
62+
# --------------------------------------------------------------------------------------
63+
# Change when properties in objects are quoted.
64+
#
65+
# "as-needed" : Only add quotes around object properties where required.
66+
# "consistent" : If at least one property in an object requires quotes, quote all properties.
67+
# "preserve" : Respect the input use of quotes in object properties.
68+
#
69+
#
70+
# @default : "as-needed"
71+
# @ref : https://prettier.io/docs/en/options.html#quote-props
72+
# --------------------------------------------------------------------------------------
73+
quoteProps: 'preserve'
74+
75+
# --------------------------------------------------------------------------------------
76+
# Use single quotes instead of double quotes in JSX.
77+
#
78+
# @default : false
79+
# @ref : https://prettier.io/docs/en/options.html#jsx-quotes
80+
# --------------------------------------------------------------------------------------
81+
jsxSingleQuote: true
82+
83+
# --------------------------------------------------------------------------------------
84+
# Print trailing commas wherever possible in multi-line comma-separated
85+
# syntactic structures.
86+
#
87+
# (A single-line array, for example, never gets trailing commas.)
88+
#
89+
# Default value changed from es5 to all in v3.0.0
90+
#
91+
# "all" : Trailing commas wherever possible (including
92+
# function parameters and calls). To run, JavaScript
93+
# code formatted this way needs an engine that
94+
# supports ES2017 (Node.js 8+ or a modern browser)
95+
# or downlevel compilation. This also enables
96+
# trailing commas in type parameters in TypeScript
97+
# (supported since TypeScript 2.7 released in January 2018).
98+
#
99+
# "es5" : Trailing commas where valid in ES5 (objects, arrays, etc.).
100+
#
101+
# Trailing commas in type parameters in TypeScript and Flow.
102+
# "none" : No trailing commas.
103+
#
104+
#
105+
# @default : "all"
106+
# @ref : https://prettier.io/docs/en/options.html#trailing-commas
107+
# --------------------------------------------------------------------------------------
108+
trailingComma: none
109+
110+
# --------------------------------------------------------------------------------------
111+
# Print spaces between brackets in object literals.
112+
#
113+
# true : Example: { foo: bar }.
114+
# false : Example: {foo: bar}.
115+
#
116+
# @default : true
117+
# @ref : https://prettier.io/docs/en/options.html#bracket-spacing
118+
# --------------------------------------------------------------------------------------
119+
bracketSpacing: true
120+
121+
# --------------------------------------------------------------------------------------
122+
# Put the > of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the
123+
# last line instead of being alone on the next line (does not apply to self closing
124+
# elements).
125+
#
126+
# true : Example:
127+
#
128+
# <button
129+
# className="prettier-class"
130+
# id="prettier-id"
131+
# onClick={this.handleClick}>
132+
# Click Here
133+
# </button>
134+
#
135+
# false : Example:
136+
#
137+
# <button
138+
# className="prettier-class"
139+
# id="prettier-id"
140+
# onClick={this.handleClick}
141+
# >
142+
# Click Here
143+
# </button>
144+
#
145+
# @default : false
146+
# @ref : https://prettier.io/docs/en/options.html#bracket-line
147+
# --------------------------------------------------------------------------------------
148+
bracketSameLine: false
149+
150+
# --------------------------------------------------------------------------------------
151+
# Include parentheses around a sole arrow function parameter.
152+
#
153+
# First available in v1.9.0, default value changed from avoid to always in v2.0.0
154+
#
155+
# "always" : Always include parens. Example: (x) => x
156+
# "avoid" : Omit parens when possible. Example: x => x
157+
#
158+
#
159+
# @default : "always"
160+
# @ref : https://prettier.io/docs/en/options.html#arrow-function-parentheses
161+
# --------------------------------------------------------------------------------------
162+
arrowParens: always
163+
164+
# --------------------------------------------------------------------------------------
165+
# By default, Prettier will not change wrapping in markdown text since some services
166+
# use a linebreak-sensitive renderer, e.g. GitHub comments and BitBucket. To have
167+
# Prettier wrap prose to the print width, change this option to "always". If you want
168+
# Prettier to force all prose blocks to be on a single line and rely on editor/viewer
169+
# soft wrapping instead, you can use "never".
170+
#
171+
# First available in v1.8.2
172+
#
173+
# "always" : Wrap prose if it exceeds the print width.
174+
# "never" : Un-wrap each block of prose into one line.
175+
# "preserve" : Do nothing, leave prose as-is. First available in v1.9.0
176+
#
177+
#
178+
# @default : "preserve"
179+
# @ref : https://prettier.io/docs/en/options.html#prose-wrap
180+
# --------------------------------------------------------------------------------------
181+
proseWrap: 'preserve'
182+
183+
# --------------------------------------------------------------------------------------
184+
# Specify the global whitespace sensitivity for HTML, Vue, Angular, and Handlebars.
185+
# See whitespace-sensitive formatting for more info.
186+
#
187+
# First available in v1.15.0. First available for Handlebars in 2.3.0
188+
#
189+
# "css" : Respect the default value of CSS display property.
190+
# For Handlebars treated same as strict.
191+
# "strict" : Whitespace (or the lack of it) around all tags is considered significant.
192+
# "ignore" : Whitespace (or the lack of it) around all tags is considered insignificant.
193+
#
194+
#
195+
# @default : "css"
196+
# @ref : https://prettier.io/docs/en/options.html#html-whitespace-sensitivity
197+
# https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting
198+
# --------------------------------------------------------------------------------------
199+
htmlWhitespaceSensitivity: 'ignore'
200+
201+
# --------------------------------------------------------------------------------------
202+
# For historical reasons, there exist two common flavors of line endings in text
203+
# files. That is:
204+
# - \n (or LF for Line Feed)
205+
# - \r\n (or CRLF for Carriage Return + Line Feed).
206+
#
207+
# The former is common on Linux and macOS, while the latter is prevalent on Windows.
208+
# Some details explaining why it is so can be found on Wikipedia.
209+
#
210+
# When people collaborate on a project from different operating systems, it becomes
211+
# easy to end up with mixed line endings in a shared git repository. It is also possible
212+
# for Windows users to accidentally change line endings in a previously committed file
213+
# from LF to CRLF. Doing so produces a large git diff and thus makes the line-by-line
214+
# history for a file (git blame) harder to explore.
215+
#
216+
# All modern text editors in all operating systems are able to correctly display line
217+
# endings when \n (LF) is used. However, old versions of Notepad for Windows will visually
218+
# squash such lines into one as they can only deal with \r\n (CRLF).
219+
#
220+
# First available in v1.15.0, default value changed from auto to lf in v2.0.0
221+
#
222+
# "lf" : Line Feed only (\n), common on Linux and macOS as well as inside git repos
223+
# "crlf" : Carriage Return + Line Feed characters (\r\n), common on Windows
224+
# "cr" : Carriage Return character only (\r), used very rarely
225+
# "auto" : Maintain existing line endings (mixed values within one file are normalised
226+
# by looking at what’s used after the first line)
227+
#
228+
# @default : "lf"
229+
# @ref : https://prettier.io/docs/en/options.html#end-of-line
230+
# --------------------------------------------------------------------------------------
231+
endOfLine: 'auto'
232+
233+
# --------------------------------------------------------------------------------------
234+
# Control whether Prettier formats quoted code embedded in the file.
235+
#
236+
# When Prettier identifies cases where it looks like you've placed some code it knows
237+
# how to format within a string in another file, like in a tagged template in
238+
# JavaScript with a tag named html or in code blocks in Markdown, it will by default try
239+
# to format that code.
240+
#
241+
# Sometimes this behavior is undesirable, particularly in cases where you might not have
242+
# intended the string to be interpreted as code. This option allows you to switch between
243+
# the default behavior (auto) and disabling this feature entirely (off).
244+
#
245+
# First available in v2.1.0
246+
#
247+
# "auto" : Format embedded code if Prettier can automatically identify it.
248+
# "off" : Never automatically format embedded code.
249+
#
250+
# @default : "auto"
251+
# @ref : https://prettier.io/docs/en/options.html#embedded-language-formatting
252+
# --------------------------------------------------------------------------------------
253+
embeddedLanguageFormatting: 'auto'
254+
255+
# --------------------------------------------------------------------------------------
256+
# Enforce single attribute per line in HTML, Vue and JSX.
257+
#
258+
# true : Enforce single attribute per line.
259+
# false : Do not enforce single attribute per line.
260+
#
261+
# @default : false
262+
# @ref : https://prettier.io/docs/en/options.html#single-attribute-per-line
263+
# --------------------------------------------------------------------------------------
264+
singleAttributePerLine: false

eslint.config.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
const tsParser = require('@typescript-eslint/parser');
2+
const js = require('@eslint/js');
3+
const globals = require('globals');
4+
const ts = require('@typescript-eslint/eslint-plugin');
5+
const eslintConfigPrettier = require('eslint-config-prettier');
6+
const prettier = require('eslint-plugin-prettier');
7+
const stylisticJs = require('@stylistic/eslint-plugin-js');
8+
9+
module.exports = [
10+
{
11+
files: [
12+
'**/*.ts',
13+
'./src/**/*.ts',
14+
'./test/**/*.ts'
15+
],
16+
plugins: {
17+
'@typescript-eslint': ts,
18+
'prettier': prettier,
19+
'@stylistic/js': stylisticJs
20+
},
21+
languageOptions: {
22+
parser: tsParser,
23+
globals: {
24+
...globals.browser,
25+
},
26+
parserOptions: {
27+
project: ['tsconfig.json'],
28+
},
29+
},
30+
rules: {
31+
...js.configs.recommended.rules,
32+
...ts.configs['stylistic-type-checked'].rules,
33+
// eslint/js rules
34+
'indent': [1, 4],
35+
'space-before-function-paren': 0,
36+
'prefer-const': 1,
37+
'comma-dangle': 0,
38+
'keyword-spacing': ['error', { 'before': true, 'after': true }],
39+
'comma-spacing': ['error', { 'before': false, 'after': true }],
40+
'indent': 0,
41+
'prefer-spread': 1,
42+
'eqeqeq': ['error', 'smart'],
43+
'no-unexpected-multiline': 0,
44+
'no-prototype-builtins': 0,
45+
'no-useless-escape': 1,
46+
'no-mixed-operators': 1,
47+
'no-control-regex': 0,
48+
'no-console': 2,
49+
'no-var': 2,
50+
'no-undef': 0,
51+
'no-redeclare': 'error',
52+
'no-unused-vars': [
53+
'error',
54+
{
55+
'argsIgnorePattern': '^_',
56+
'varsIgnorePattern': '^_',
57+
'ignoreRestSiblings': true
58+
}
59+
],
60+
'@stylistic/js/no-multi-spaces': [0, { ignoreEOLComments: true }],
61+
'@stylistic/js/arrow-spacing': ['error', { 'before': true, 'after': true }],
62+
'@stylistic/js/arrow-parens': ['error', 'always'],
63+
'@stylistic/js/block-spacing': ['error', 'always'],
64+
'@stylistic/js/brace-style': ['error', 'allman', { 'allowSingleLine': true }],
65+
'@stylistic/js/comma-dangle': ['error', 'never'],
66+
'@stylistic/js/comma-spacing': ['error', { 'before': false, 'after': true }],
67+
'@stylistic/js/computed-property-spacing': ['error', 'always'],
68+
'@stylistic/js/eol-last': ['error', 'always'],
69+
'@stylistic/js/jsx-quotes': ['error', 'prefer-single'],
70+
'@stylistic/js/linebreak-style': ['error', 'unix'],
71+
'@stylistic/js/no-mixed-spaces-and-tabs': ['error'],
72+
'@stylistic/js/no-tabs': ['error'],
73+
'@stylistic/js/no-trailing-spaces': ['error', { 'skipBlankLines': true, 'ignoreComments': true }],
74+
'@stylistic/js/no-whitespace-before-property': ['error'],
75+
'@stylistic/js/object-curly-spacing': ['error', 'always'],
76+
'@stylistic/js/quote-props': ['error', 'as-needed'],
77+
'@stylistic/js/quotes': ['error', 'single', { 'allowTemplateLiterals': true }],
78+
'@stylistic/js/semi': ['error', 'never'],
79+
'@stylistic/js/space-in-parens': ['error', 'always'],
80+
'@stylistic/js/space-infix-ops': ['error'],
81+
'@stylistic/js/spaced-comment': ['error', 'always'],
82+
'@stylistic/js/template-curly-spacing': ['error', 'always'],
83+
'@stylistic/js/template-tag-spacing': ['error', 'always'],
84+
'@stylistic/js/wrap-iife': [2, "inside", { functionPrototypeMethods: true }],
85+
86+
// 'prettier/prettier': ['error'],
87+
88+
// @typescript-eslint rules
89+
'@typescript-eslint/prefer-nullish-coalescing': 'off' // require `strictNullChecks`
90+
},
91+
}];

0 commit comments

Comments
 (0)