Skip to content

nextcloud-libraries/eslint-config

Folders and files

NameName
Last commit message
Last commit date
Mar 26, 2025
Jul 8, 2024
Mar 26, 2025
Mar 26, 2025
Oct 11, 2024
Feb 14, 2025
Jul 8, 2024
Mar 25, 2025
Sep 23, 2019
Mar 26, 2025
Feb 15, 2025
Feb 14, 2025
Mar 31, 2025
Mar 31, 2025
Feb 16, 2025
Feb 15, 2025

Repository files navigation

@nextcloud/eslint-config

REUSE status npm last version Lint status Dependabot status

This is a package containing the unified global eslint config used by all nextcloud apps and libraries. It contains the necessary dependencies and peerDependencies so that other apps cannot update if this config does not support it. Please always use dependabot to update your apps, OR pay attention to the peer dependencies error messages!

Installation

npm install @nextcloud/eslint-config --save-dev

Usage

Note

Since version 9 this package depends on ESLint 9, which uses the new flat config system.

This package provides some predefined configurations you can choose from. For the recommended setup add a file eslint.config.js in the root directory of your app repository with the following content:

import { recommended } from '@nextcloud/eslint-config'

export default [
	...recommended,
]

Available configurations

Instead of the recommended configuration this package also provides some alternatives, depending on your app setup you can also choose:

  • recommended
    • General rules including code style
    • Support for Typescript
    • Support for Vue 3
    • Support Vue files with Typescript syntax (the script within .vue files will be handled as Typescript).
  • recommendedJavascript
    • Same as recommended but Vue files (the script part) will be handled as Javascript.
  • recommendedVue2
    • Same as recommended but Vue files are considered in Vue 2 syntax.
  • recommendedVue2Javascript
    • Same as recommended but Vue files are considered in Vue 2 syntax and the script part will be handled as Javascript instead of Typescript.

Configurations for Nextcloud libraries

For libraries some of the presets make no sense, like checking Nextcloud deprecated API. But on the otherhand some rules should be enforced, like documenting all properties. So for libraries use following configurations:

  • recommendedLibrary
  • recommendedVue2Library

Bundled plugins

This configuration also provides some bundled plugins with new rules, those options are already included in the recommended configurations.

It is possible to override the recommended configurations:

// eslint.config.js
import { recommended } from '@nextcloud/eslint-config'
export default [
	...recommended,
	{
		files: ['**/*.js'],
		rules: {
			// Make deprecations error instead of warning level
			'@nextcloud/no-deprecations': ['error'],
		}
	}
]

You can even use the plugins without using the Nextcloud ESLint config:

// eslint.config.js
import { nextcloudPlugin } from '@nextcloud/eslint-config'
export default [
	{
		files: ['**/*.js'],
		plugins: {
			'@nextcloud': nextcloudPlugin,
		},
		rules: {
			'@nextcloud/no-removed-apis': ['error', { targetVersion: '29.0.0' }],
		},
	}
]

package-json plugin

Rules:

  • sort-package-json
    • Ensures the package.json is sorted in consistent order
    • Included as error level in recommended configurations

@nextcloud plugin

Rules:

  • no-deprecations
    • Report usage of deprecated Nextcloud API
    • Included as warn level in recommended configuration
    • Available options
      {
        /**
         * Limit deprecated API to specified Nextcloud version
         * @example '29.0.0'
         * @default ''
         */
        targetVersion?: string
        /**
         * Try to find appinfo.xml to detect targetVersion
         * @default true
         */
        parseAppInfo?: boolean
      }
  • no-removed-apis
    • Report usage of removed Nextcloud API
    • Included as error level in recommended configuration
    • Available options
      {
        /**
         * Limit removed API to specified Nextcloud version
         * @example '29.0.0'
         * @default ''
         */
        targetVersion?: string
        /**
         * Try to find appinfo.xml to detect targetVersion
         * @default true
         */
        parseAppInfo?: boolean
      }

@nextcloud-l10n

import { l10nPlugin  } from '@nextcloud/eslint-config'

Rules:

  • enforce-ellipsis
    • Enforce consistent usageof ellipsis instead of tripple dots
    • Included as error level in recommended configuration
  • non-breaking-space
    • Enforce non-breaking spaces before ellipsis
    • Included as error level in recommended configuration

Adding custom overrides

Sometimes additional rules need to be added for individual projects, and while we do not recommend to override Nextcloud rules for code style (it should be consistent across all Nextcloud projects!), it is possible to add such custom rules.

For example to enforce chains to be on separate lines:

- const a = foo().then((a) => a.b).catch((e) => e.c)
+ const a = foo()
+ 	.then((a) => a.b)
+ 	.catch((e) => e.c)

Adjust your eslint.config.js like this:

import { recommended } from '@nextcloud/eslint-config'

export default [
	...recommended,
	{
		rules: {
			'@stylistic/newline-per-chained-call': ['error'],
		}
	},
]

Release new version

  1. Update CHANGELOG.md file with the latest changes
  2. Bump the package version with npm version
  3. Push version bump commit
  4. Create a new release with proper changelog https://github.com/nextcloud-libraries/eslint-config/releases/new