Skip to content

Commit a1fe102

Browse files
authored
Chore: Update eslint and its config, clean up some lint (#3293)
1 parent c7b131d commit a1fe102

File tree

18 files changed

+2957
-1301
lines changed

18 files changed

+2957
-1301
lines changed

.eslintrc.json

-63
This file was deleted.

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ lint-scss:
196196

197197
.PHONY: lint-js
198198
lint-js:
199-
@npx eslint --ignore-path .gitignore "**/*.{js,jsx,ts,tsx}"
199+
@npx eslint
200200

201201

202202
# encrypted config file

RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Updated styles, sass, style linting [#3294](https://github.com/Automattic/simplenote-electron/pull/3294)
88
- Upgraded dependencies [#3292](https://github.com/Automattic/simplenote-electron/pull/3292)
99
- Updated the ID type used for analytics to avoid sending invalid WPCOM IDs [#3291](https://github.com/Automattic/simplenote-electron/pull/3291)
10+
- Updated eslint configuration [#3293](https://github.com/Automattic/simplenote-electron/pull/3293)
1011

1112
## [v2.23.1]
1213

after_sign_hook.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = async function (params) {
4949
`Could not begin signing macOS build. Errors: ${errors.join('\n')}`
5050
);
5151
} else {
52-
console.log('All required env vars found. Moving on...');
52+
console.log('All required env vars found. Moving on...'); // eslint-disable-line no-console
5353
}
5454
}
5555

desktop/updater/manual-updater/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class ManualUpdater extends Updater {
6767
const releaseConfig = yaml.load(configBody);
6868

6969
if (semver.lt(app.getVersion(), releaseConfig.version)) {
70-
// eslint-disable-next-line no-console
7170
log.info(
7271
'New update is available, prompting user to update to',
7372
releaseConfig.version

eslint.config.mjs

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import typescriptEslint from '@typescript-eslint/eslint-plugin';
2+
import react from 'eslint-plugin-react';
3+
import jest from 'eslint-plugin-jest';
4+
import prettier from 'eslint-plugin-prettier';
5+
import reactHooks from 'eslint-plugin-react-hooks';
6+
import { fixupPluginRules } from '@eslint/compat';
7+
import globals from 'globals';
8+
import tsParser from '@typescript-eslint/parser';
9+
import path from 'node:path';
10+
import { fileURLToPath } from 'node:url';
11+
import js from '@eslint/js';
12+
import { FlatCompat } from '@eslint/eslintrc';
13+
14+
const __filename = fileURLToPath(import.meta.url);
15+
const __dirname = path.dirname(__filename);
16+
const compat = new FlatCompat({
17+
baseDirectory: __dirname,
18+
recommendedConfig: js.configs.recommended,
19+
allConfig: js.configs.all,
20+
});
21+
22+
export default [
23+
{
24+
ignores: ['dist/', 'eslint.config.mjs'],
25+
},
26+
...compat.extends(
27+
'eslint:recommended',
28+
'plugin:@typescript-eslint/eslint-recommended',
29+
'plugin:jest/recommended',
30+
'prettier',
31+
'plugin:prettier/recommended',
32+
'plugin:react/recommended'
33+
),
34+
{
35+
plugins: {
36+
'@typescript-eslint': typescriptEslint,
37+
react,
38+
jest,
39+
prettier,
40+
'react-hooks': fixupPluginRules(reactHooks),
41+
},
42+
43+
languageOptions: {
44+
globals: {
45+
...globals.browser,
46+
...jest.environments.globals.globals,
47+
...globals.mocha,
48+
...globals.node,
49+
},
50+
51+
parser: tsParser,
52+
ecmaVersion: 6,
53+
sourceType: 'module',
54+
55+
parserOptions: {
56+
ecmaFeatures: {
57+
jsx: true,
58+
},
59+
},
60+
},
61+
62+
settings: {
63+
react: {
64+
version: 'detect',
65+
},
66+
},
67+
68+
rules: {
69+
eqeqeq: ['error', 'always'],
70+
'no-console': 'warn',
71+
'no-lonely-if': 'error',
72+
'no-shadow': 'warn',
73+
'no-spaced-func': 'error',
74+
75+
'prettier/prettier': [
76+
'error',
77+
{
78+
singleQuote: true,
79+
},
80+
],
81+
82+
'react/display-name': 'warn',
83+
'react/no-deprecated': 'warn',
84+
'react/no-string-refs': 'warn',
85+
'react/prop-types': 'off',
86+
'vars-on-top': 'error',
87+
},
88+
},
89+
{
90+
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
91+
92+
rules: {
93+
'no-unused-vars': 'off',
94+
},
95+
},
96+
];

lib/analytics/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const analytics = {
4646
const fullEventName = `${prefix}_${eventName}`;
4747
const fullEventProperties = {
4848
...eventProperties,
49-
device_info_app_version: config.version, // eslint-disable-line no-undef
49+
device_info_app_version: config.version,
5050
};
5151

5252
debug(`${fullEventName}: %o`, fullEventProperties);

lib/analytics/tracks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function buildTracks() {
6666
const tokens = host.split('.');
6767
let tryDomain: string;
6868
if (typeof TRACKS_COOKIE_DOMAIN !== 'undefined') {
69-
cookieDomain = TRACKS_COOKIE_DOMAIN; // eslint-disable-line no-undef
69+
cookieDomain = TRACKS_COOKIE_DOMAIN;
7070
} else {
7171
for (let i = 1; i <= tokens.length; ++i) {
7272
tryDomain = '.' + tokens.slice(-i).join('.');

lib/app-layout/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ const mapStateToProps: S.MapState<StateProps> = (state) => ({
164164
isSmallScreen: selectors.isSmallScreen(state),
165165
openedRevision:
166166
state.ui.openedRevision?.[0] === state.ui.openedNote
167-
? state.data.noteRevisions
167+
? (state.data.noteRevisions
168168
.get(state.ui.openedNote)
169-
?.get(state.ui.openedRevision?.[1]) ?? null
169+
?.get(state.ui.openedRevision?.[1]) ?? null)
170170
: null,
171171
openedNote: state.ui.openedNote,
172172
showNoteList: state.ui.showNoteList,

lib/dialogs/about/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CrossIcon from '../../icons/cross';
55
import TopRightArrowIcon from '../../icons/arrow-top-right';
66
import Dialog from '../../dialog';
77

8-
const appVersion = config.version; // eslint-disable-line no-undef
8+
const appVersion = config.version;
99

1010
type OwnProps = {
1111
closeDialog: () => void;

lib/icon-button/index.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ export const IconButton = ({ icon, title, ...props }: Props) => (
1515
enterDelay={200}
1616
title={title}
1717
>
18-
<button
19-
aria-label={title}
20-
className="icon-button"
21-
type="button"
22-
data-title={title}
23-
{...props}
24-
>
25-
{icon}
26-
</button>
18+
<span>
19+
<button
20+
aria-label={title}
21+
className="icon-button"
22+
type="button"
23+
data-title={title}
24+
{...props}
25+
>
26+
{icon}
27+
</button>
28+
</span>
2729
</Tooltip>
2830
);
2931

lib/note-toolbar/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const mapStateToProps: S.MapState<StateProps> = ({
166166
ui: { editMode, openedNote },
167167
simperium: { connectionStatus },
168168
}) => {
169-
const note = openedNote ? data.notes.get(openedNote) ?? null : null;
169+
const note = openedNote ? (data.notes.get(openedNote) ?? null) : null;
170170

171171
return {
172172
editMode,

lib/revision-selector/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class RevisionSelector extends Component<Props> {
177177
</button>
178178
<button
179179
aria-label={`Restore revision from ${revisionDate}`}
180-
disabled={isNewest}
180+
disabled={!!isNewest}
181181
className="button button-primary button-compact"
182182
onClick={this.onAcceptRevision}
183183
>
@@ -196,7 +196,7 @@ const mapStateToProps: S.MapState<StateProps> = (state) => {
196196
const noteId = state.ui.openedNote;
197197
const openedRevision =
198198
state.ui.openedRevision?.[0] === state.ui.openedNote
199-
? state.ui.openedRevision?.[1] ?? null
199+
? (state.ui.openedRevision?.[1] ?? null)
200200
: null;
201201
const restoreDeletedTags = state.ui.restoreDeletedTags;
202202

lib/search/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const toSearchNote = (note: Partial<T.Note>): SearchNote => ({
4242
creationDate: note.creationDate ?? Date.now() / 1000,
4343
modificationDate: note.modificationDate ?? Date.now() / 1000,
4444
isPinned: note.systemTags?.includes('pinned') ?? false,
45-
isTrashed: !!note.deleted ?? false,
45+
isTrashed: !!note.deleted,
4646
});
4747

4848
export const tagsFromSearch = (query: string) => {
@@ -311,8 +311,8 @@ export const middleware: S.Middleware = (store) => {
311311
const noteAt = filteredNotes.findIndex((noteId) => noteId === openedNote);
312312
const nextNoteToOpen =
313313
noteAt === -1
314-
? filteredNotes[0] ?? null
315-
: filteredNotes[noteAt + 1] ?? filteredNotes[noteAt - 1] ?? null;
314+
? (filteredNotes[0] ?? null)
315+
: (filteredNotes[noteAt + 1] ?? filteredNotes[noteAt - 1] ?? null);
316316

317317
return {
318318
...action,

lib/utils/export/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const exportZipArchive = (notes: Map<T.EntityId, T.Note>) => {
1212
return exportNotes(notes)
1313
.then(exportToZip)
1414
.then((zip) =>
15-
zip.generateAsync({
15+
zip?.generateAsync({
1616
compression: 'DEFLATE',
1717
platform: get(window, 'process.platform', 'DOS'),
1818
type: 'blob',

0 commit comments

Comments
 (0)