Skip to content

Commit

Permalink
feat: update eslint and rebuild config
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Oct 27, 2024
1 parent 4208f6b commit 11104e1
Show file tree
Hide file tree
Showing 25 changed files with 1,641 additions and 730 deletions.
136 changes: 136 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/* eslint-disable n/no-extraneous-import */
// @ts-check

import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import eslint from '@eslint/js'
import neslint from 'eslint-plugin-n'
import tseslint from 'typescript-eslint'
import reacteslint from 'eslint-plugin-react'
import hookseslint from 'eslint-plugin-react-hooks'
import reactRefreshEslint from 'eslint-plugin-react-refresh'

export default [
// setup the parser first
{
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: true,
},
},
},

{
...neslint.configs['flat/recommended-script'],
ignores: [...(neslint.configs['flat/recommended-script'].ignores ?? []), 'webui/**/*'],
},
{
// extends: commonExtends,
plugins: {
'@typescript-eslint': tseslint.plugin,
},
rules: {
// Default rules to be applied everywhere
'prettier/prettier': 'error',

...eslint.configs.recommended.rules,

'no-console': 'off',

'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_', varsIgnorePattern: '^_(.+)' },
],
'no-extra-semi': 'off',
// 'n/no-unsupported-features/es-syntax': ['error', { ignores: ['modules'] }],
'no-use-before-define': 'off',
'no-warning-comments': ['error', { terms: ['nocommit', '@nocommit', '@no-commit'] }],
// 'jest/no-mocks-import': 'off',
},
},
...tseslint.configs.recommendedTypeChecked,
{
// disable type-aware linting on JS files
files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
...tseslint.configs.disableTypeChecked,
},
{
files: ['*.mjs'],
languageOptions: {
sourceType: 'module',
},
},
{
files: ['**/*.tsx', '**/*.ts', '**/*.cts', '**/*.mts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/explicit-module-boundary-types': ['error'],
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-await': 'off', // conflicts with 'promise-function-async'

/** Disable some annoyingly strict rules from the 'recommended-requiring-type-checking' pack */
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-argument': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/restrict-template-expressions': 0,
'@typescript-eslint/restrict-plus-operands': 0,
'@typescript-eslint/no-redundant-type-constituents': 0,
/** End 'recommended-requiring-type-checking' overrides */
},
},
{
files: ['**/__tests__/**/*', 'test/**/*'],
rules: {
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
},
},

// Add prettier at the end to give it final say on formatting
eslintPluginPrettierRecommended,
{
// But lastly, ensure that we ignore certain paths
ignores: [
'**/dist/*',
'**/build/*',
'/dist',
'**/pkg/*',
'**/docs/*',
'**/generated/*',
'**/node_modules/*',
'**/electron-output/*',
'webui/vite.config.ts',
],
},
{
files: ['eslint.config.*'],
rules: {
'n/no-unpublished-import': 'off',
},
},

// The above is mostly copied from https://github.com/bitfocus/companion-module-tools/blob/main/eslint/config.mjs with very little modifications. The below is extra rules that have been added
{
files: ['webui/**/*.tsx', 'webui/**/*.jsx', 'webui/**/*.ts', 'webui/**/*.js'],
plugins: {
'react-hooks': hookseslint,
'react-refresh': reactRefreshEslint,
react: reacteslint,
},
rules: {
...hookseslint.configs.recommended.rules,
'react-refresh/only-export-components': 'warn',
},
},
{
rules: {
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-duplicate-type-constituents': 'off',
},
},
]
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,26 @@
"dev:electron": "yarn workspace satellite dev:electron",
"dev:webui": "yarn workspace webui dev",
"build": "yarn workspaces foreach --all run build",
"lint": "yarn workspaces foreach --all run lint",
"lint:raw": "eslint",
"lint": "eslint .",
"license-validate": "sofie-licensecheck",
"dist": "run build && zx tools/build_electron.mjs"
},
"devDependencies": {
"@sofie-automation/eslint-plugin": "^0.1.1",
"@tsconfig/node20": "^20.1.4",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-n": "^17.11.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"typescript": "~5.2.2",
"typescript-eslint": "^8.11.0",
"zx": "^8.1.9"
},
"engines": {
Expand Down
7 changes: 4 additions & 3 deletions pi-image/update-prompt/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ const ALLOWED_VERSIONS = '^1.5.0'
let currentVersion
try {
currentVersion = fs.readFileSync('/opt/companion-satellite/BUILD').toString().trim()
} catch (e) {
} catch (_e) {
// Assume none installed
}

async function getLatestBuildsForBranch(branch, targetCount) {
targetCount *= 10 // HACK until the api changes
// eslint-disable-next-line no-undef

// eslint-disable-next-line n/no-unsupported-features/node-builtins
const data = await fetch(
`https://api.bitfocus.io/v1/product/companion-satellite/packages?branch=${branch}&limit=${targetCount}`,
)
Expand All @@ -38,7 +39,7 @@ async function getLatestBuildsForBranch(branch, targetCount) {
published: new Date(pkg.published),
})
}
} catch (e) {
} catch (_e) {
// Not a semver tag, so ignore
}
}
Expand Down
1 change: 0 additions & 1 deletion satellite/.eslintignore

This file was deleted.

53 changes: 0 additions & 53 deletions satellite/.eslintrc.cjs

This file was deleted.

Loading

0 comments on commit 11104e1

Please sign in to comment.