Home / File/ eslint.config.js — svelte Source File

eslint.config.js — svelte Source File

Architecture documentation for eslint.config.js, a javascript file in the svelte codebase. 2 imports, 0 dependents.

File javascript Compiler Parser 2 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  83580498_6b95_ad34_2b87_490a227f300f["eslint.config.js"]
  fe62edb0_d78c_6d7b_6f2c_8c7248cf7499["eslint-config"]
  83580498_6b95_ad34_2b87_490a227f300f --> fe62edb0_d78c_6d7b_6f2c_8c7248cf7499
  87710be0_e1c2_5bfb_084a_106601b34b59["eslint-plugin-lube"]
  83580498_6b95_ad34_2b87_490a227f300f --> 87710be0_e1c2_5bfb_084a_106601b34b59
  style 83580498_6b95_ad34_2b87_490a227f300f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import svelte_config from '@sveltejs/eslint-config';
import lube from 'eslint-plugin-lube';

const no_compiler_imports = {
	meta: {
		type: /** @type {const} */ ('problem'),
		docs: {
			description:
				'Enforce that there are no imports to the compiler in runtime code. ' +
				'This prevents accidental inclusion of the compiler runtime and ' +
				"ensures that TypeScript does not pick up more ambient types (for example from Node) that shouldn't be available in the browser."
		}
	},
	create(context) {
		return {
			Program: () => {
				// Do a simple string search because ESLint doesn't provide a way to check JSDoc comments.
				// The string search could in theory yield false positives, but in practice it's unlikely.
				const text = context.sourceCode.getText();
				const idx = Math.max(text.indexOf('../compiler/'), text.indexOf('#compiler'));
				if (idx !== -1) {
					context.report({
						loc: {
							start: context.sourceCode.getLocFromIndex(idx),
							end: context.sourceCode.getLocFromIndex(idx + 12)
						},
						message:
							'References to compiler code are forbidden in runtime code (both for type and value imports)'
					});
				}
			}
		};
	}
};

/** @type {import('eslint').Linter.Config[]} */
export default [
	...svelte_config,
	{
		languageOptions: {
			parserOptions: {
				projectService: true,
				tsconfigRootDir: import.meta.dirname
			}
		},
		plugins: {
			lube,
			custom: { rules: { no_compiler_imports } }
		},
		rules: {
			'@typescript-eslint/await-thenable': 'error',
			'@typescript-eslint/require-await': 'error',
			'no-console': 'error',
			'lube/svelte-naming-convention': ['error', { fixSameNames: true }],
			// eslint isn't that well-versed with JSDoc to know that `foo: /** @type{..} */ (foo)` isn't a violation of this rule, so turn it off
			'object-shorthand': 'off',
			// eslint is being a dummy here too
			'@typescript-eslint/prefer-promise-reject-errors': 'off',
			'no-var': 'off',

			// TODO: enable these rules and run `pnpm lint:fix`
			// skipping that for now so as to avoid impacting real work
			'@stylistic/quotes': 'off',
			'@typescript-eslint/no-unused-vars': 'off',
			'prefer-const': 'off'
		}
	},
	{
		// If you get an error along the lines of "@typescript-eslint/await-thenable needs a project service configured", then that likely means
		// that eslint rules that need to be type-aware run through a Svelte file which seems unsupported at the moment. In that case, ensure that
		// these are excluded to run on Svelte files.
		files: ['**/*.svelte'],
		rules: {
			'@typescript-eslint/await-thenable': 'off',
			'@typescript-eslint/prefer-promise-reject-errors': 'off',
			'@typescript-eslint/require-await': 'off'
		}
	},
	{
		files: ['packages/svelte/src/**/*'],
		ignores: ['packages/svelte/src/compiler/**/*'],
		rules: {
			'custom/no_compiler_imports': 'error',
			'svelte/no-svelte-internal': 'off'
		}
	},
	{
		ignores: [
			'**/*.d.ts',
			'**/tests',
			'packages/svelte/scripts/process-messages/templates/*.js',
			'packages/svelte/scripts/_bundle.js',
			'packages/svelte/src/compiler/errors.js',
			'packages/svelte/src/internal/client/errors.js',
			'packages/svelte/src/internal/client/warnings.js',
			'packages/svelte/src/internal/shared/warnings.js',
			'packages/svelte/src/internal/server/warnings.js',
			'packages/svelte/compiler/index.js',
			// stuff we don't want to lint
			'benchmarking/**',
			'coverage/**',
			'playgrounds/sandbox/**',
			// exclude top level config files
			'*.config.js',
			'vitest-xhtml-environment.ts',
			// documentation can contain invalid examples
			'documentation',
			'tmp/**'
		]
	}
];

Domain

Subdomains

Dependencies

  • eslint-config
  • eslint-plugin-lube

Frequently Asked Questions

What does eslint.config.js do?
eslint.config.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Parser subdomain.
What functions are defined in eslint.config.js?
eslint.config.js defines 1 function(s): no_compiler_imports.create.
What does eslint.config.js depend on?
eslint.config.js imports 2 module(s): eslint-config, eslint-plugin-lube.
Where is eslint.config.js in the architecture?
eslint.config.js is located at eslint.config.js (domain: Compiler, subdomain: Parser).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free