mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +02:00
# Description of Changes Adds an eslint rule to disallow importing any Tauri APIs outside the desktop folder to help hint to developers that they should be following the frontend architecture. While doing this, I also discovered that you can provide a custom message in the `no-restricted-imports` rule, which is nicer than the comments that I'd previously added to the eslint config file to explain why they weren't allowed: ```text /Users/jamesbrunton/Dev/spdf1/frontend/src/core/components/shared/config/configSections/GeneralSection.tsx 19:1 error 'src/core/contexts/PreferencesContext' import is restricted from being used by a pattern. Use @app/* imports instead of absolute src/ imports no-restricted-imports 20:1 error '../../../../../core/contexts/AppConfigContext' import is restricted from being used by a pattern. Use @app/* imports instead of relative imports no-restricted-imports 21:1 error '@tauri-apps/core' import is restricted from being used by a pattern. Tauri APIs are desktop-only. Review frontend/DeveloperGuide.md for structure advice no-restricted-imports ```
117 lines
3.5 KiB
JavaScript
117 lines
3.5 KiB
JavaScript
// @ts-check
|
|
|
|
import eslint from '@eslint/js';
|
|
import globals from 'globals';
|
|
import { defineConfig } from 'eslint/config';
|
|
import tseslint from 'typescript-eslint';
|
|
|
|
const srcGlobs = [
|
|
'src/**/*.{js,mjs,jsx,ts,tsx}',
|
|
];
|
|
const nodeGlobs = [
|
|
'scripts/**/*.{js,ts,mjs}',
|
|
'*.config.{js,ts,mjs}',
|
|
];
|
|
|
|
const baseRestrictedImportPatterns = [
|
|
{ regex: '^\\.', message: "Use @app/* imports instead of relative imports." },
|
|
{ regex: '^src/', message: "Use @app/* imports instead of absolute src/ imports." },
|
|
];
|
|
|
|
export default defineConfig(
|
|
{
|
|
// Everything that contains 3rd party code that we don't want to lint
|
|
ignores: [
|
|
'dist',
|
|
'node_modules',
|
|
'public',
|
|
'src-tauri',
|
|
],
|
|
},
|
|
eslint.configs.recommended,
|
|
tseslint.configs.recommended,
|
|
{
|
|
rules: {
|
|
'no-restricted-imports': [
|
|
'error',
|
|
{
|
|
patterns: baseRestrictedImportPatterns,
|
|
},
|
|
],
|
|
'@typescript-eslint/no-empty-object-type': [
|
|
'error',
|
|
{
|
|
// Allow empty extending interfaces because there's no real reason not to, and it makes it obvious where to put extra attributes in the future
|
|
allowInterfaces: 'with-single-extends',
|
|
},
|
|
],
|
|
'@typescript-eslint/no-explicit-any': 'off', // Temporarily disabled until codebase conformant
|
|
'@typescript-eslint/no-require-imports': 'off', // Temporarily disabled until codebase conformant
|
|
'@typescript-eslint/no-unused-vars': [
|
|
'error',
|
|
{
|
|
'args': 'all', // All function args must be used (or explicitly ignored)
|
|
'argsIgnorePattern': '^_', // Allow unused variables beginning with an underscore
|
|
'caughtErrors': 'all', // Caught errors must be used (or explicitly ignored)
|
|
'caughtErrorsIgnorePattern': '^_', // Allow unused variables beginning with an underscore
|
|
'destructuredArrayIgnorePattern': '^_', // Allow unused variables beginning with an underscore
|
|
'varsIgnorePattern': '^_', // Allow unused variables beginning with an underscore
|
|
'ignoreRestSiblings': true, // Allow unused variables when removing attributes from objects (otherwise this requires explicit renaming like `({ x: _x, ...y }) => y`, which is clunky)
|
|
},
|
|
],
|
|
},
|
|
},
|
|
// Desktop-only packages must not be imported from core or proprietary code.
|
|
// Use the stub/shadow pattern instead: define a stub in src/core/ and override in src/desktop/.
|
|
{
|
|
files: srcGlobs,
|
|
ignores: ['src/desktop/**'],
|
|
rules: {
|
|
'no-restricted-imports': [
|
|
'error',
|
|
{
|
|
patterns: [
|
|
...baseRestrictedImportPatterns,
|
|
{
|
|
regex: '^@tauri-apps/',
|
|
message: "Tauri APIs are desktop-only. Review frontend/DeveloperGuide.md for structure advice.",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
// Folders that have been cleaned up and are now conformant - stricter rules enforced here
|
|
{
|
|
files: ['src/saas/**/*.{js,mjs,jsx,ts,tsx}'],
|
|
languageOptions: {
|
|
parserOptions: {
|
|
project: true,
|
|
tsconfigRootDir: import.meta.dirname,
|
|
},
|
|
},
|
|
rules: {
|
|
'@typescript-eslint/no-explicit-any': 'error',
|
|
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
|
},
|
|
},
|
|
// Config for browser scripts
|
|
{
|
|
files: srcGlobs,
|
|
languageOptions: {
|
|
globals: {
|
|
...globals.browser,
|
|
}
|
|
}
|
|
},
|
|
// Config for node scripts
|
|
{
|
|
files: nodeGlobs,
|
|
languageOptions: {
|
|
globals: {
|
|
...globals.node,
|
|
}
|
|
}
|
|
},
|
|
);
|