
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
eslint-config-liferay
Advanced tools
An ESLint shareable config that helps enforce the Liferay Frontend Guidelines.
| Preset | Extends | Description |
|---|---|---|
liferay | eslint:recommended, prettier | Base configuration, suitable for general projects |
react | liferay | liferay, plus rules from eslint-plugin-react and react-hooks, suitable for projects that use React |
metal | react | Like react, but turns off rules that cause false positives in Metal components |
portal | react | Default for projects inside liferay-portal itself |
$ npm install --save-dev eslint eslint-config-liferay
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.
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.
For React projects outside of liferay-portal, you can extend liferay/react instead:
module.exports = {
extends: ['liferay/react'],
};
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.jscopyright.jsmid-level/
.eslintrc.jscopyright.jsbottom-level/
.eslintrc.jsIf 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.
eslint-plugin-liferayThe bundled eslint-plugin-liferay plugin includes the following rules:
Array.isArray() over instanceof Array.require statements use destructuring.import and require grouping.className attributes.import of any given module per file.require() calls use static arguments.it() descriptions start with a verb, not with "should".require() call at the top level is not immediately called.it() etc).className attributes.import and require ordering.import statements.className attributes do not have leading or trailing whitespace.eslint-plugin-liferay-portalThe bundled eslint-plugin-liferay-portal plugin includes the following rules:
@deprecated annotations.metal-* plugins and utilities.ReactDOM.render in favor of our wrapper.sideNavigation plugin.MIT
FAQs
ESLint shareable config for the Liferay JavaScript Style
We found that eslint-config-liferay demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?

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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.