Skip to content

Commit a2dc436

Browse files
authored
chore: add linting to the base (#61)
1 parent fe7ae71 commit a2dc436

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+793
-621
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"url": "https://github.com/SAP/ui5-webcomponents.git"
1616
},
1717
"scripts": {
18-
"build": "npm-run-all --sequential build:core build:main build:playground",
18+
"build": "npm-run-all --sequential build:core build:base build:main build:playground",
1919
"build:core": "cd packages/core && yarn build",
20+
"build:base": "cd packages/base && yarn build",
2021
"build:main": "cd packages/main && yarn build",
2122
"build:docs": "cd packages/main && yarn build:docs",
2223
"build:api": "cd packages/main && yarn build:api",
@@ -25,8 +26,8 @@
2526
"clean:core": "cd packages/core && yarn clean",
2627
"clean:main": "cd packages/main && yarn clean",
2728
"clean:playground": "cd packages/playground && yarn clean",
28-
"serve": "cross-env DEV=true yarn build:core && cross-env DEV=true yarn build:main && npm-run-all --parallel serve:webcomponents serve:playground",
29-
"serve:es5": "cross-env DEV=true yarn build:core && cross-env DEV=true yarn build:main && npm-run-all --parallel serve:webcomponents:es5 serve:playground",
29+
"serve": "cross-env DEV=true yarn build:core && cross-env DEV=true yarn build:base && cross-env DEV=true yarn build:main && npm-run-all --parallel serve:webcomponents serve:playground",
30+
"serve:es5": "cross-env DEV=true yarn build:core && cross-env DEV=true yarn build:base && cross-env DEV=true yarn build:main && npm-run-all --parallel serve:webcomponents:es5 serve:playground",
3031
"start": "npm run serve",
3132
"start:es5": "npm run serve:es5",
3233
"serve:webcomponents": "cd packages/main && yarn dev",

packages/base/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Note: Changes to this file also must be applied to the top level .eslintignore file.
2+
test

packages/base/.eslintrc.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es6": true
5+
},
6+
"root": true,
7+
"extends": "airbnb-base",
8+
"parserOptions": {
9+
"ecmaVersion": 2018,
10+
"sourceType": "module"
11+
},
12+
"rules": {
13+
"comma-dangle": [2, "always-multiline"], // difference from openui5
14+
"no-cond-assign": 2,
15+
"no-console": 2,
16+
"no-constant-condition": 2,
17+
"no-control-regex": 2,
18+
"no-debugger": 2,
19+
"no-dupe-args": 2,
20+
"no-dupe-keys": 2,
21+
"no-duplicate-case": 2,
22+
"no-empty-character-class": 2,
23+
"no-empty": 2,
24+
"no-ex-assign": 2,
25+
"no-extra-boolean-cast": 1,
26+
"no-extra-parens": [2, "functions"],
27+
"no-extra-semi": 2,
28+
"no-func-assign": 2,
29+
"no-inner-declarations": [2, "functions"],
30+
"no-invalid-regexp": 2,
31+
"no-irregular-whitespace": 2,
32+
"no-negated-in-lhs": 2,
33+
"no-obj-calls": 2,
34+
"no-regex-spaces": 2,
35+
"no-sparse-arrays": 2,
36+
"no-trailing-spaces": 2,
37+
"no-unreachable": 2,
38+
"use-isnan": 2,
39+
// "valid-jsdoc": [1, { removed for UI5 WebComponents
40+
// "requireReturn": false
41+
// }],
42+
"valid-typeof": 2,
43+
44+
"accessor-pairs": 2,
45+
"block-scoped-var": 1,
46+
// "consistent-return": 1, // removed for UI5 WebComponents
47+
"curly": [2, "all"],
48+
// "default-case": 1, // removed for UI5 WebComponents
49+
"no-alert": 2,
50+
"no-caller": 2,
51+
"no-div-regex": 2,
52+
"no-eval": 2,
53+
"no-extend-native": 2,
54+
"no-extra-bind": 2,
55+
"no-fallthrough": 2,
56+
"no-floating-decimal": 2,
57+
"no-implied-eval": 2,
58+
"no-iterator": 2,
59+
"no-labels": 2,
60+
"no-lone-blocks": 2,
61+
"no-loop-func": 2,
62+
"no-native-reassign": 2,
63+
"no-new-func": 2,
64+
"no-new-wrappers": 1,
65+
"no-new": 1,
66+
"no-octal-escape": 2,
67+
"no-octal": 2,
68+
"no-proto": 2,
69+
"no-redeclare": 1,
70+
"no-return-assign": 2,
71+
"no-script-url": 2,
72+
"no-self-compare": 2,
73+
"no-sequences": 2,
74+
"no-unused-expressions": 1,
75+
"no-void": 2,
76+
"no-warning-comments": 0,
77+
"no-with": 2,
78+
"radix": [2, "as-needed"],
79+
"wrap-iife": [2, "any"],
80+
"yoda": 2,
81+
82+
"strict": [2, "function"],
83+
84+
"no-catch-shadow": 2,
85+
"no-delete-var": 2,
86+
"no-label-var": 2,
87+
"no-shadow-restricted-names": 2,
88+
"no-undef-init": 2,
89+
"no-undef": 2,
90+
"no-unused-vars": [2, {"vars":"all", "args":"none"}],
91+
"no-use-before-define": [1, "nofunc"],
92+
93+
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
94+
"camelcase": [1, { "properties": "never" }], // added for UI5 WebComponents
95+
"consistent-this": [1, "that"],
96+
"linebreak-style": 2,
97+
"max-nested-callbacks": [1, 3],
98+
"new-cap": 1,
99+
"new-parens": 2,
100+
"no-array-constructor": 2,
101+
"no-lonely-if": 1,
102+
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
103+
"no-nested-ternary": 2,
104+
"no-new-object": 2,
105+
"no-spaced-func": 2,
106+
"quote-props": [2, "as-needed", { "keywords": true, "unnecessary": false }],
107+
"semi-spacing": [1, {"before": false, "after": true}],
108+
"semi": 2,
109+
"keyword-spacing": 2,
110+
"space-infix-ops": 2,
111+
"space-unary-ops": [2, { "words": true, "nonwords": false }],
112+
// airbnb overrides
113+
"indent": [2, "tab"],
114+
"no-underscore-dangle": 0,
115+
"no-tabs": 0,
116+
"quotes": [2, "double", { "allowTemplateLiterals": true }],
117+
"no-useless-constructor": 0,
118+
"no-param-reassign": 0,
119+
"one-var": 0,
120+
"max-len": 0,
121+
"arrow-parens": [2, "as-needed"],
122+
"class-methods-use-this": 0,
123+
"no-plusplus": 0,
124+
"default-case": 0,
125+
"consistent-return": 0,
126+
"prefer-destructuring": 0,
127+
"arrow-body-style": 0,
128+
"import/no-unresolved": 0,
129+
"no-use-before-define": 0
130+
}
131+
};

packages/base/package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@
1414
"url": "https://github.com/SAP/ui5-webcomponents.git"
1515
},
1616
"scripts": {
17-
"clean": "rimraf dist"
17+
"build": "npm run lint",
18+
"clean": "rimraf dist",
19+
"lint": "eslint ."
1820
},
1921
"dependencies": {
2022
"@polymer/polymer": "^3.1.0",
21-
"@ui5/webcomponents-core": "0.7.0"
23+
"@ui5/webcomponents-core": "0.7.0",
24+
"lit-html": "^0.14.0"
25+
},
26+
"devDependencies": {
27+
"eslint": "^5.13.0",
28+
"eslint-config-airbnb-base": "^13.1.0"
2229
},
2330
"resolutions": {
31+
"abstract-syntax-tree": "1.0.3",
2432
"dir-glob": "2.0.0"
2533
}
2634
}

packages/base/src/sap/ui/webcomponents/base/.eslintrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/base/src/sap/ui/webcomponents/base/Bootstrap.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import './shims/Core-shim';
1+
import "./shims/Core-shim";
22
import "./shims/jquery-shim";
33

4-
import ShadowDOM from './compatibility/ShadowDOM';
5-
import whenDOMReady from './util/whenDOMReady';
4+
import ShadowDOM from "./compatibility/ShadowDOM";
5+
import whenDOMReady from "./util/whenDOMReady";
66
import EventEnrichment from "./events/EventEnrichment";
77
import patchNodeValue from "./compatibility/patchNodeValue";
88
import IconFonts from "./IconFonts";
@@ -18,21 +18,19 @@ let bootPromise;
1818

1919
const Bootstrap = {
2020

21-
boot: function() {
21+
boot() {
2222
if (bootPromise) {
2323
return bootPromise;
2424
}
2525

26-
bootPromise = new Promise(function (resolve, reject) {
27-
whenDOMReady().then(function() {
28-
26+
bootPromise = new Promise(resolve => {
27+
whenDOMReady().then(() => {
2928
// This will only have effect if the polyfill is loaded
3029
attachThemeChange(ShadowDOM._applyTheme);
3130

3231
IconFonts.load();
3332
DOMEventHandler.start();
3433
resolve();
35-
3634
});
3735
});
3836

packages/base/src/sap/ui/webcomponents/base/CLDR.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable camelcase */
12
import ar from "@ui5/webcomponents-core/dist/sap/ui/core/cldr/ar.json";
23
import ar_EG from "@ui5/webcomponents-core/dist/sap/ui/core/cldr/ar_EG.json";
34
import ar_SA from "@ui5/webcomponents-core/dist/sap/ui/core/cldr/ar_SA.json";
@@ -149,40 +150,43 @@ const cldrData = {
149150
zh_HK,
150151
zh_SG,
151152
zh_TW,
152-
}
153+
};
153154

154155
const allEntriesInlined = Object.entries(cldrData).every(([_key, value]) => typeof (value) === "object");
156+
/* eslint-disable */
155157
if (allEntriesInlined) {
156-
console.warn(`Inefficient bundling detected: consider bundling CLDR imports as URLs instead of inlining them.
158+
console.warn(`Inefficient bundling detected: consider bundling CLDR imports as URLs instead of inlining them.
157159
See rollup-plugin-url or webpack file-loader for more information.
158160
Suggested pattern: "cldr\\\/.*\\\.json"`);
159161
}
162+
/* eslint-enable */
163+
160164

161165
const M_ISO639_OLD_TO_NEW = {
162-
"iw" : "he",
163-
"ji" : "yi",
164-
"in" : "id",
165-
"sh" : "sr"
166+
"iw": "he",
167+
"ji": "yi",
168+
"in": "id",
169+
"sh": "sr",
166170
};
167171

168172
const calcLocale = (language, region, script) => {
169173
// normalize language and handle special cases
170174
language = (language && M_ISO639_OLD_TO_NEW[language]) || language;
171175
// Special case 1: in an SAP context, the inclusive language code "no" always means Norwegian Bokmal ("nb")
172-
if ( language === "no" ) {
176+
if (language === "no") {
173177
language = "nb";
174178
}
175179
// Special case 2: for Chinese, derive a default region from the script (this behavior is inherited from Java)
176-
if ( language === "zh" && !region ) {
177-
if ( script === "Hans" ) {
180+
if (language === "zh" && !region) {
181+
if (script === "Hans") {
178182
region = "CN";
179-
} else if ( script === "Hant" ) {
183+
} else if (script === "Hant") {
180184
region = "TW";
181185
}
182186
}
183187

184188
// try language + region
185-
let localeId = language + "_" + region;
189+
let localeId = `${language}_${region}`;
186190
if (!cldrData[localeId]) {
187191
// fallback to language only
188192
localeId = language;
@@ -193,14 +197,14 @@ const calcLocale = (language, region, script) => {
193197
}
194198

195199
return localeId;
196-
}
200+
};
197201

198-
const fetchCldrData = async (language, region, script) => {
202+
const fetchCldrData = async (language, region, script) => {
199203
const localeId = calcLocale(language, region, script);
200204

201-
if (typeof(cldrData[localeId]) === "object") {
205+
if (typeof (cldrData[localeId]) === "object") {
202206
// inlined from build
203-
registerModuleContent(`sap/ui/core/cldr/${localeId}.json`, JSON.stringify(cldrData[localeId]))
207+
registerModuleContent(`sap/ui/core/cldr/${localeId}.json`, JSON.stringify(cldrData[localeId]));
204208
return cldrData[localeId];
205209
}
206210

@@ -214,4 +218,5 @@ const registerCldrUrl = (locale, url) => {
214218
cldrData[locale] = url;
215219
};
216220

217-
export { fetchCldrData, registerCldrUrl };
221+
export { fetchCldrData, registerCldrUrl };
222+
/* eslint-enable camelcase */

packages/base/src/sap/ui/webcomponents/base/Configuration.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@ import Configuration from "@ui5/webcomponents-core/dist/sap/ui/core/Configuratio
22

33
function readConfiguration() {
44
function normalize(o) {
5-
for (var i in o) {
6-
var v = o[i];
7-
var il = i.toLowerCase();
8-
if ( !o.hasOwnProperty(il) ) {
5+
for (const i in o) { // eslint-disable-line
6+
const v = o[i];
7+
const il = i.toLowerCase();
8+
if (!o.hasOwnProperty(il)) { // eslint-disable-line
99
o[il] = v;
1010
delete o[i];
1111
}
1212
}
1313
return o;
1414
}
1515

16-
var jsonConfig = document.querySelector("[data-id='sap-ui-config']");
16+
const jsonConfig = document.querySelector("[data-id='sap-ui-config']");
1717
if (jsonConfig && jsonConfig.type === "application/json") {
1818
return normalize(JSON.parse(jsonConfig.innerHTML));
1919
}
2020
return {};
2121
}
2222

23-
window['sap-ui-config'] = readConfiguration();
23+
window["sap-ui-config"] = readConfiguration();
2424
const configuration = new Configuration();
2525

2626
if (configuration.getTheme() === "base") {
2727
configuration._setTheme("sap_fiori_3");
2828
}
2929

30-
export default configuration;
30+
export default configuration;

packages/base/src/sap/ui/webcomponents/base/ControlRenderer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const RendererImpl = LitRenderer;
55
// window.renderStats = new Map();
66

77
class ControlRenderer {
8-
98
static render(control) {
109
// const oldCounter = window.renderStats.get(control.tagName) || 0;
1110
// window.renderStats.set(control.tagName, oldCounter + 1);
@@ -17,7 +16,6 @@ class ControlRenderer {
1716

1817
RendererImpl.render(renderResult, root);
1918
}
20-
2119
}
2220

2321
export default ControlRenderer;

0 commit comments

Comments
 (0)