<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

ESLint plugin

SWAN's ESLint package is a custom linting plugin designed to enforce the Vista Design System's evolving design language across JavaScript and TypeScript files. It helps developers write consistent and accessible SWAN-specific code by identifying deviations from SWANโ€™s design principles and coding conventions, thereby reducing variations.

Getting started

Prerequisites

You will need to have ESLint setup done for your project. Refer to Getting Started with ESLint if you don't have a setup.

Peer dependencies

This plugin requires the following peer dependencies to be installed in your project:

Environment support

We recommend a minimum Node.js version of "18.18.0" for a predictable, stable experience. It is also in accordance with ESLint setup requirements. Versions below may/may not work.

Installation

Usage

This plugin provides a recommended ESLint configuration preloaded with SWAN-specific rules. You can integrate it into your project using either the flat config format (ESLint v9+) or the legacy .eslintrc format (< ESLint v9).

Flat ESLint Config (>= ESLint v9)

If you're using the flat config format, extend the recommended setup like this:

Legacy ESLint Config (< ESLint v9)

TypeScript Projects: Type-Aware Rule Setup

Some rules in this plugin (like @vp/swan/no-deprecated) use TypeScript's type information to provide more accurate linting. These "type-aware" rules require special configuration to work properly.

When You Need This Setup

When your main tsconfig.json only covers certain directories (like src/), but ESLint needs to lint files outside those foldersโ€”such as tests, configuration files, or scripts. You may also need this setup if you encounter errors about missing type information during linting.

How to Configure

Create a dedicated tsconfig.eslint.json in your project root:

And then update your ESLint config to use it:

Rules

Each rule has its own README with usage, rationale, and examples.

Rule IDDescriptionDefault SeverityDocs with examplesSuggestion available
@vp/swan/enforce-grid-structureEnforces consistent grid structure across layouts.errorREADME-
@vp/swan/no-internal-tokensDisallows use of internal SWAN tokens like SwanInternal*, SwanComp*.errorREADMENo
@vp/swan/no-internal-componentsDisallows usage of internal-only SWAN components.errorREADMENo
@vp/swan/no-deprecated-tokensFlags deprecated tokens from the design system.errorREADMEPartially
@vp/swan/no-deprecatedFlags deprecated code patterns/components.errorREADMEPartially
@vp/swan/required-accessibility-propsEnsures accessibility-related props (like aria-*) are used where needed.errorREADMEYes
@vp/swan/enforce-font-skinEnforce usage of fontSkin prop for consistent font stylingwarnREADMEPartially
@vp/swan/no-mixed-font-propsDisallows mixing fontSkin with individual typography props like fontSize, fontWeight, or fontFamily.errorREADME-
@vp/swan/no-classnameDisallow the use of SWAN classes (such as swan-* class) on either any components or elements.errorREADME-

Overriding a rule

You can override individual rule severities even when using the recommended config.

Flat Config Example

Legacy .eslintrc Example

FAQs

Update your ESLint version to 8.45 or above.

Related