🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more
Socket
Book a DemoInstallSign in
Socket

eslint-config-liferay

Package Overview
Dependencies
Maintainers
15
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-config-liferay

ESLint shareable config for the Liferay JavaScript Style

latest
Source
npmnpm
Version
21.1.0
Version published
Maintainers
15
Created
Source

eslint-config-liferay

An ESLint shareable config that helps enforce the Liferay Frontend Guidelines.

Overview

PresetExtendsDescription
liferayeslint:recommended, prettierBase configuration, suitable for general projects
reactliferayliferay, plus rules from eslint-plugin-react and react-hooks, suitable for projects that use React
metalreactLike react, but turns off rules that cause false positives in Metal components
portalreactDefault for projects inside liferay-portal itself

Installation

$ npm install --save-dev eslint eslint-config-liferay

Usage

Once the eslint-config-liferay package is installed, you can use it by specifying liferay in the extends section of your ESLint configuration.

module.exports = {
	extends: ['liferay'],
};

This preset provides a reasonable starting point for an independent open source project.

liferay-portal

In liferay-portal itself we extend the liferay/portal preset instead, which activates some rules specific to liferay-portal. This preset assumes the use of React, and also provides a set of custom rules that are described in detail in the eslint-plugin-liferay-portal section below.

This extension is applied automatically by liferay-npm-scripts, so you don't have to configure it explicitly.

An important disclaimer about the use of ESLint in liferay-portal

JavaScript code that appears inline inside JSP files and other templates is only lightly checked by ESLint, because JSP is an impoverished environment where we have to work with context-free snippets of text as opposed to fully-formed, valid JS modules. Our long-term strategy is to move as much code as possible out of JSP and into React components, but in the interim, please be aware that the level of safety provided by the linter inside JSP is greatly reduced.

React

For React projects outside of liferay-portal, you can extend liferay/react instead:

module.exports = {
	extends: ['liferay/react'],
};

metal-jsx

For legacy projects inside liferay-portal that use metal-jsx, we have a "metal" preset:

module.exports = {
	extends: ['liferay/metal'],
};

Use this preset to stop ESLint from spuriously warning that variables that are used as JSX components are unused.

The included eslint-plugin-notice plug-in can be used to enforce the use of uniform copyright headers across a project by placing a template named copyright.js in the project root (for example, see the file defining the headers used in eslint-config-liferay itself) and configuring the rule:

const path = require('path');

module.exports = {
	extends: ['liferay'],
	rules: {
		'notice/notice': [
			'error',
			{
				templateFile: path.join(__dirname, 'copyright.js'),
			},
		],
	},
};

Explicit configuration is required in order to make overrides possible; for example:

  • top-level/
    • .eslintrc.js
    • copyright.js
    • mid-level/
      • .eslintrc.js
      • copyright.js
      • bottom-level/
        • .eslintrc.js

If we were to provide configuration by default, then if bottom-level/.eslintrc.js does an extends: ['liferay'], then the default configuration would be considered more local than the one provided by mid-level, causing the wrong copyright.js to be used.

Base rules

Rule or presetWhere we use itNotes
eslint-config-prettierliferayPreset that turns off ESLint rules that conflict with Prettier
eslint:recommendedliferayPreset bundled with ESLint
default-caseliferay#30
liferay-portal/deprecationliferay/portal#55
liferay-portal/no-explicit-extendliferay/portal#54
liferay-portal/no-global-fetchliferay/portal#62
liferay-portal/no-loader-import-specifierliferay/portal#122
liferay-portal/no-metal-pluginsliferay/portal#61
liferay-portal/no-react-dom-renderliferay/portal#71
liferay-portal/no-side-navigationliferay/portal#44
liferay/array-is-arrayliferay#139
liferay/destructure-requiresliferay#94
liferay/group-importsliferay#60
liferay/import-extensionsliferay#137
liferay/imports-firstliferay#60
liferay/no-absolute-importliferay#60
liferay/no-arrowliferay#179
liferay/no-duplicate-class-namesliferay#108
liferay/no-duplicate-importsliferay#60
liferay/no-dynamic-requireliferay#60
liferay/no-it-shouldliferay#43
liferay/no-require-and-callliferay#94
liferay/padded-test-blocksliferay#75
liferay/sort-importsliferay#60
liferay/sort-import-destructuresliferay#124
liferay/sort-class-namesliferay#108
liferay/trim-class-namesliferay#108
no-consoleliferay#79
no-for-of-loops/no-for-of-loopsliferay#30
no-only-tests/no-only-testsliferay#22
no-restricted-globalsliferay/portal#109
no-return-assignliferay#30
no-unused-expressionsliferay#19
no-unused-varsliferay#30
notice/noticeliferay#26
object-shorthandliferay#30
prefer-constliferay#30
quote-propsliferay#30
radixliferay#66
react-hooks/exhaustive-depsliferay/reactRules of Hooks
react-hooks/rules-of-hooksliferay/reactRules of Hooks
react/forbid-foreign-prop-typesliferay/react#301
react/jsx-fragmentsliferay/react#58
react/jsx-keyliferay/react#42
react/jsx-no-comment-textnodesliferay/react#42
react/jsx-no-duplicate-propsliferay/react#42
react/jsx-no-undefliferay/react#42
react/jsx-sort-propsliferay/react#58
react/jsx-uses-reactliferay/react#42
react/jsx-uses-varsliferay/react, liferay/metal#42, #50
react/no-children-propliferay/react#42
react/no-danger-with-childrenliferay/react#42
react/no-direct-mutation-stateliferay/react#42
react/no-is-mountedliferay/react#42
react/no-render-return-valueliferay/react#42
react/no-string-refsliferay/react#42
react/no-unescaped-entitiesliferay/react#42
react/no-unknown-propertyliferay/react#42
react/require-render-returnliferay/react#42
sort-destructure-keys/sort-destructure-keysliferay#60
sort-keysliferay#63

Custom rules

eslint-plugin-liferay

The bundled eslint-plugin-liferay plugin includes the following rules:

eslint-plugin-liferay-portal

The bundled eslint-plugin-liferay-portal plugin includes the following rules:

License

MIT

Keywords

code

FAQs

Package last updated on 07 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts