xo

repository·main·Indexed 27 days ago

https://github.com/xojs/xo

An opinionated, zero-config JavaScript/TypeScript linter that acts as a wrapper around ESLint. It provides strict, readable defaults and includes plugins to eliminate code style discussions. Supports ESM projects and integrates with Astro, React, Svelte, and Vue. Features include automatic TypeScript linting, Prettier integration, and a CLI with options for indentation, semicolons, and automatic fixing.

Tokens
4.8K
Snippets
17
Records
45
Agent score
93%

What's inside xo

  1. Use XO rules with ESLint (without XO CLI)

    main

    If you want to use XO's rules directly in ESLint without using the xo CLI, install eslint-config-xo. This configuration accepts core style options, including Prettier integration.

    Note: This replaces the deprecated xoToEslintConfig helper. Use eslintConfigXo() instead.

    import eslintConfigXo from 'eslint-config-xo';
    
    export default [
    	...eslintConfigXo({space: true, prettier: true}),
    ];
  2. Integrate XO with React

    main

    To lint React files, install eslint-config-xo-react and spread its recommended config in your xo.config.js.

    Note: Until eslint-plugin-react supports ESLint 10 natively, you may need to wrap the config with fixupConfigRules from @eslint/compat.

    npm install --save-dev eslint-config-xo-react
    import xoReact from 'eslint-config-xo-react';
    
    const xoConfig = [
    	...xoReact(),
    ];
    
    export default xoConfig;
  3. Configure XO via xo.config.js or xo.config.ts

    main

    XO uses ESLint's Flat Config format. You can create an xo.config.js or xo.config.ts file in your project root, or add an xo field to your package.json. For TypeScript validation of your config, import the provided types.

    import {type FlatXoConfig} from 'xo';
    
    const xoConfig: FlatXoConfig = [
    	// your config
    ];
    
    export default xoConfig;
  4. Use XO rules with ESLint (with XO CLI/Editor Integration)

    main

    If you use the xo CLI but your editor only supports the ESLint extension, you can use the xo/eslint-adapter. This adapter reads your xo.config.js and automatically generates a matching ESLint configuration, ensuring your editor displays the same errors as the CLI.

    export {default} from 'xo/eslint-adapter';
  5. Integrate XO with Svelte

    main

    To lint Svelte files, install eslint-plugin-svelte and spread its recommended config in your xo.config.js.

    npm install --save-dev eslint-plugin-svelte
    import sveltePlugin from 'eslint-plugin-svelte';
    
    const xoConfig = [
    	...sveltePlugin.configs.recommended,
    ];
    
    export default xoConfig;
  6. Integrate XO with Astro

    main

    To lint Astro files, install eslint-plugin-astro and spread its recommended config in your xo.config.js.

    npm install --save-dev eslint-plugin-astro
    import astroPlugin from 'eslint-plugin-astro';
    
    const xoConfig = [
    	...astroPlugin.configs.recommended,
    ];
    
    export default xoConfig;
  7. Integrate XO with Vue

    main

    To lint Vue files, install eslint-plugin-vue and spread its recommended config in your xo.config.js.

    npm install --save-dev eslint-plugin-vue
    import vuePlugin from 'eslint-plugin-vue';
    
    const xoConfig = [
    	...vuePlugin.configs['flat/recommended'],
    ];
    
    export default xoConfig;
  8. Configure TypeScript linting in XO

    main

    XO automatically lints TypeScript files (.ts, .mts, .cts, and .tsx) using eslint-config-xo-typescript. It handles the @typescript-eslint/parser project option automatically, even without a tsconfig.json.

    To opt out of automatic tsconfig handling, specify your own languageOptions.parserOptions.project, languageOptions.parserOptions.projectService, or languageOptions.parserOptions.tsconfigRootDir in your configuration.

  9. Suppress ESLint violations using eslint-suppressions.json

    main

    XO respects an eslint-suppressions.json file in your working directory. This allows you to suppress existing violations while enforcing rules on new code.

    To generate this file, use the xo/eslint-adapter in an eslint.config.js and run ESLint with the --suppress-all flag:

    npx eslint --suppress-all

    To use a custom path for the suppressions file, use the --suppressions-location flag with the xo CLI.

  10. Configure file selection and ignores

    main

    files

    Specify which files the config applies to using a glob string or array. Default: **/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,vue,svelte,astro}.

    ignores

    Add paths to be ignored. For global ignores, keep ignores as the only key in the config object. XO supports negated ignores (e.g., !dist/**) to reopen built-in ignored paths.

  11. Configure Prettier with the prettier option

    main

    Enable Prettier formatting by setting prettier: true. Alternatively, set prettier: 'compat' to turn off all XO rules that conflict with Prettier, allowing you to manage formatting via a separate Prettier configuration.

    When true, XO applies specific Prettier options: semi (based on your semicolon setting), useTabs (based on your space setting), tabWidth (based on your space setting), singleQuote: true, bracketSpacing: false, bracketSameLine: false, and trailingComma: 'all'.