-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
172 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
!jest.config.js | ||
!jest.setup.js | ||
!.eslintrc.js | ||
!eslint.config.js | ||
node_modules | ||
dist | ||
out | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import guardian from '@guardian/eslint-config'; | ||
|
||
export default [ | ||
{ | ||
ignores: [ | ||
'dist', | ||
'jest.dist.*', // depends on build output, so don't lint it | ||
'.wireit', | ||
'storybook-static', | ||
], | ||
}, | ||
...guardian.configs.recommended, | ||
...guardian.configs.jest, | ||
...guardian.configs.react, | ||
{ | ||
rules: { | ||
'no-unused-vars': 'off', | ||
|
||
'@typescript-eslint/no-unused-vars': [ | ||
'warn', | ||
{ | ||
argsIgnorePattern: '^_', | ||
varsIgnorePattern: '^_', | ||
caughtErrorsIgnorePattern: '^_', | ||
}, | ||
], | ||
|
||
// 'prettier/prettier': 'warn', | ||
|
||
'react/no-unknown-property': [ | ||
'error', | ||
{ | ||
ignore: ['css'], | ||
}, | ||
], | ||
|
||
'no-restricted-syntax': [ | ||
'error', | ||
{ | ||
message: | ||
"Don't use `fetch` directly, please use the `pandaFetch` abstraction, to get automatic session refreshes", | ||
selector: "CallExpression[callee.name='fetch']", | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
// import { fixupConfigRules } from '@eslint/compat'; | ||
// import typescriptEslint from '@typescript-eslint/eslint-plugin'; | ||
// import prettier from 'eslint-plugin-prettier'; | ||
// import globals from 'globals'; | ||
// import tsParser from '@typescript-eslint/parser'; | ||
// import path from 'node:path'; | ||
// import { fileURLToPath } from 'node:url'; | ||
// import js from '@eslint/js'; | ||
// import { FlatCompat } from '@eslint/eslintrc'; | ||
|
||
// const __filename = fileURLToPath(import.meta.url); | ||
// const __dirname = path.dirname(__filename); | ||
// const compat = new FlatCompat({ | ||
// baseDirectory: __dirname, | ||
// recommendedConfig: js.configs.recommended, | ||
// allConfig: js.configs.all, | ||
// }); | ||
|
||
// export default [ | ||
// { | ||
// ignores: ['**/*.css', '**/*.svg'], | ||
// }, | ||
// ...fixupConfigRules( | ||
// compat.extends( | ||
// '@guardian/eslint-config-typescript', | ||
// 'prettier', | ||
// 'plugin:react/recommended', | ||
// 'plugin:react/jsx-runtime', | ||
// 'plugin:react-hooks/recommended', | ||
// ), | ||
// ), | ||
// { | ||
// plugins: { | ||
// '@typescript-eslint': typescriptEslint, | ||
// prettier, | ||
// }, | ||
|
||
// languageOptions: { | ||
// globals: { | ||
// ...globals.browser, | ||
// ...globals.node, | ||
// }, | ||
|
||
// parser: tsParser, | ||
// }, | ||
|
||
// settings: { | ||
// react: { | ||
// version: 'detect', | ||
// }, | ||
// }, | ||
|
||
// rules: { | ||
// 'no-unused-vars': 'off', | ||
|
||
// '@typescript-eslint/no-unused-vars': [ | ||
// 'warn', | ||
// { | ||
// argsIgnorePattern: '^_', | ||
// varsIgnorePattern: '^_', | ||
// caughtErrorsIgnorePattern: '^_', | ||
// }, | ||
// ], | ||
|
||
// 'prettier/prettier': 'warn', | ||
|
||
// 'react/no-unknown-property': [ | ||
// 'error', | ||
// { | ||
// ignore: ['css'], | ||
// }, | ||
// ], | ||
|
||
// 'no-restricted-syntax': [ | ||
// 'error', | ||
// { | ||
// message: | ||
// "Don't use `fetch` directly, please use the `pandaFetch` abstraction, to get automatic session refreshes", | ||
// selector: "CallExpression[callee.name='fetch']", | ||
// }, | ||
// ], | ||
// }, | ||
// }, | ||
// { | ||
// files: ['**/*.ts', '**/*.tsx'], | ||
|
||
// languageOptions: { | ||
// ecmaVersion: 5, | ||
// sourceType: 'script', | ||
|
||
// parserOptions: { | ||
// project: ['./tsconfig.json', './tsconfig.*.json'], | ||
// }, | ||
// }, | ||
// }, | ||
// ]; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
/* eslint-disable no-restricted-syntax -- this file provides the abstraction over `fetch`, so is allowed to call it directly */ | ||
|
||
/** | ||
* A customised version of `fetch`, that will attempt to re-auth the user on login failure. | ||
*/ | ||
export const pandaFetch: typeof fetch = async (...args) => { | ||
/* eslint-disable-next-line no-restricted-syntax -- this is the definition of 'pandaFetch' that we're asking people to use instead of fetch, but it needs to use fetch itself*/ | ||
const response = await fetch(...args); | ||
if (response.status !== 419) | ||
if (response.status !== 419) { | ||
// succeeded; return the response | ||
return response; | ||
} | ||
|
||
// refresh the auth session | ||
/* eslint-disable-next-line no-restricted-syntax -- this is the definition of 'pandaFetch' that we're asking people to use instead of fetch, but it needs to use fetch itself*/ | ||
await fetch('/', { mode: 'no-cors', credentials: 'include' }); | ||
// reattempt the fetch, return the result no matter the expiry | ||
/* eslint-disable-next-line no-restricted-syntax -- this is the definition of 'pandaFetch' that we're asking people to use instead of fetch, but it needs to use fetch itself*/ | ||
return fetch(...args); | ||
}; |