eslint-plugin-ui5
raw JSON → 0.1.0 verified Sat Apr 25 auth: no javascript
An ESLint plugin providing custom lint rules for UI5 development (OpenUI5/SAPUI5). Version 0.1.0 is the initial release, maintained as needed for UI5 projects. It includes rules to prevent common pitfalls like using global IDs, synchronous module access via global names, for...in loops, and boolean literal comparisons. Differentiates from generic ESLint by specifically targeting UI5 conventions and best practices.
Common errors
error Error: Failed to load plugin 'ui5' declared in '.eslintrc': Cannot find module 'eslint-plugin-ui5' ↓
cause Plugin not installed in the project.
fix
Run 'npm install eslint-plugin-ui5 --save-dev'.
error ESLint: TypeError: Cannot read property 'no-global-id' of undefined ↓
cause Rule name misspelled or plugin not loaded correctly.
fix
Ensure plugin is listed in 'plugins' array and rule name is correct (e.g., 'ui5/no-global-id').
error ReferenceError: sap is not defined ↓
cause Code expects SAP UI5 globals without declaring them.
fix
Add 'globals' in .eslintrc: { "globals": { "sap": "readonly" } }.
Warnings
gotcha Must have ESLint installed as a peer dependency; plugin will not work without it. ↓
fix Run 'npm install eslint --save-dev' in your project.
gotcha Global install of ESLint requires global install of this plugin as well. ↓
fix Install both globally: npm install -g eslint eslint-plugin-ui5
deprecated Rule 'hungarian-notation' is stylistic and may be removed in future versions. ↓
fix Consider using alternative naming conventions or disabling the rule.
Install
npm install eslint-plugin-ui5 yarn add eslint-plugin-ui5 pnpm add eslint-plugin-ui5 Imports
- rules wrong
const rules = require('eslint-plugin-ui5').rulescorrectimport { rules } from 'eslint-plugin-ui5' - configs
import { configs } from 'eslint-plugin-ui5' - Plugin usage in .eslintrc wrong
plugins: ['eslint-plugin-ui5']correctplugins: ['ui5']
Quickstart
// Install dependencies
// npm install eslint eslint-plugin-ui5 --save-dev
// .eslintrc.json
{
"plugins": ["ui5"],
"rules": {
"ui5/no-global-id": "error",
"ui5/no-global-name": "error",
"ui5/no-for-in": "warn",
"ui5/no-boolean-literal-compare": "error",
"ui5/hungarian-notation": "warn"
}
}
// Example file: MyControl.js
sap.ui.define([
"sap/ui/core/Control"
], function (Control) {
return Control.extend("my.Control", {
renderer: {
render: function (oRM, oControl) {
// This will trigger no-global-id
var oCore = sap.ui.getCore();
var oById = oCore.byId("myId"); // Error if rule enabled
}
}
});
});