Skip to content

Commit 69a605e

Browse files
committed
feat(lint): add eslint and airbnb rules
1 parent 1a33c79 commit 69a605e

File tree

6 files changed

+1065
-75
lines changed

6 files changed

+1065
-75
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*]
2+
end_of_line = lf
3+
insert_final_newline = true

.eslintrc.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
extends: [
7+
'airbnb-base',
8+
],
9+
parserOptions: {
10+
ecmaVersion: 'latest',
11+
sourceType: 'module',
12+
},
13+
rules: {
14+
'no-param-reassign': 'off',
15+
},
16+
};

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"browser": "dist/vuecloak.umd.js",
88
"scripts": {
99
"build": "rimraf dist && rollup -c rollup.config.js",
10+
"lint": "eslint --ext .js --fix src/",
1011
"test": "echo \"Error: no test specified\" && exit 1"
1112
},
1213
"repository": {
@@ -28,6 +29,9 @@
2829
},
2930
"homepage": "https://github.com/vilaboim/vuecloak#readme",
3031
"devDependencies": {
32+
"eslint": "^7.32.0 || ^8.2.0",
33+
"eslint-config-airbnb-base": "^15.0.0",
34+
"eslint-plugin-import": "^2.25.2",
3135
"rimraf": "^3.0.2",
3236
"rollup": "^2.52.7"
3337
},

src/devtools.js

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { setupDevtoolsPlugin } from '@vue/devtools-api'
1+
import { setupDevtoolsPlugin } from '@vue/devtools-api';
22

3-
let isAlreadyInstalled = false
4-
const INSPECTOR_ID = 'vuecloak'
3+
let isAlreadyInstalled = false;
4+
const INSPECTOR_ID = 'vuecloak';
55

6-
export function devtoolsPlugin (app, keycloak) {
7-
const keycloakProperties = Object.keys(keycloak).filter(key => typeof keycloak[key] !== 'function')
8-
const keycloakMethods = ['loadUserProfile', 'loadUserInfo']
6+
export default function devtoolsPlugin(app, keycloak) {
7+
const keycloakProperties = Object.keys(keycloak).filter((key) => typeof keycloak[key] !== 'function');
8+
const keycloakMethods = ['loadUserProfile', 'loadUserInfo'];
99

1010
setupDevtoolsPlugin(
1111
{
@@ -21,63 +21,63 @@ export function devtoolsPlugin (app, keycloak) {
2121
id: INSPECTOR_ID,
2222
label: 'Vuecloak',
2323
icon: 'lock',
24-
treeFilterPlaceholder: 'Search for property...'
25-
})
24+
treeFilterPlaceholder: 'Search for property...',
25+
});
2626

27-
api.on.getInspectorTree(payload => {
27+
api.on.getInspectorTree((payload) => {
2828
if (payload.inspectorId === INSPECTOR_ID) {
2929
const rootNodes = [
3030
{
3131
id: 'properties',
3232
label: 'Properties',
3333
children: keycloakProperties.map((property) => ({
3434
id: property,
35-
label: property
36-
}))
37-
}
38-
]
35+
label: property,
36+
})),
37+
},
38+
];
3939

4040
if (keycloak.authenticated) {
4141
rootNodes.push({
4242
id: 'methods',
4343
label: 'Methods',
4444
children: keycloakMethods.map((property) => ({
4545
id: property,
46-
label: property
47-
}))
48-
})
46+
label: property,
47+
})),
48+
});
4949
}
5050

51-
payload.rootNodes = rootNodes
51+
payload.rootNodes = rootNodes;
5252
}
53-
})
53+
});
5454

5555
api.on.getInspectorState(async (payload) => {
5656
if (payload.inspectorId === INSPECTOR_ID) {
57-
const nodeId = payload.nodeId
57+
const { nodeId } = payload;
5858

5959
if (keycloak.authenticated && keycloakMethods.includes(nodeId)) {
6060
payload.state = {
6161
[nodeId]: {
6262
key: nodeId,
6363
value: await keycloak[nodeId](),
64-
editable: false
65-
}
66-
}
64+
editable: false,
65+
},
66+
};
6767
} else {
6868
payload.state = {
6969
[nodeId]: {
7070
key: nodeId,
7171
value: keycloak[nodeId],
72-
editable: false
73-
}
74-
}
72+
editable: false,
73+
},
74+
};
7575
}
7676
}
77-
})
77+
});
7878
}
7979

80-
isAlreadyInstalled = true
81-
}
82-
)
80+
isAlreadyInstalled = true;
81+
},
82+
);
8383
}

src/index.js

+48-46
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,77 @@
1-
import Keycloak from 'keycloak-js'
2-
import { devtoolsPlugin } from './devtools'
1+
import Keycloak from 'keycloak-js';
2+
import devtoolsPlugin from './devtools';
33

4-
function isFunction (value) {
5-
return typeof value === 'function'
4+
function isFunction(value) {
5+
return typeof value === 'function';
66
}
77

8-
function init (config, options) {
9-
const keycloak = Keycloak(config)
8+
function init(config, options) {
9+
const keycloak = Keycloak(config);
1010

11-
keycloak.onReady = function () {
12-
isFunction(options.onReady) && options.onReady(keycloak)
13-
}
11+
keycloak.onReady = () => {
12+
if (isFunction(options.onReady)) options.onReady(keycloak);
13+
};
1414

15-
keycloak.onAuthSuccess = function () {
16-
isFunction(options.onAuthSuccess) && options.onAuthSuccess(keycloak)
17-
}
15+
keycloak.onAuthSuccess = () => {
16+
if (isFunction(options.onAuthSuccess)) options.onAuthSuccess(keycloak);
17+
};
1818

19-
keycloak.onAuthError = function () {
20-
isFunction(options.onAuthError) && options.onAuthError(keycloak)
21-
}
19+
keycloak.onAuthError = () => {
20+
if (isFunction(options.onAuthError)) options.onAuthError(keycloak);
21+
};
2222

23-
keycloak.onAuthRefreshSuccess = function () {
24-
isFunction(options.onAuthRefreshSuccess) && options.onAuthRefreshSuccess(keycloak)
25-
}
23+
keycloak.onAuthRefreshSuccess = () => {
24+
if (isFunction(options.onAuthRefreshSuccess)) options.onAuthRefreshSuccess(keycloak);
25+
};
2626

27-
keycloak.onAuthRefreshError = function () {
28-
isFunction(options.onAuthRefreshError) && options.onAuthRefreshError(keycloak)
29-
}
27+
keycloak.onAuthRefreshError = () => {
28+
if (isFunction(options.onAuthRefreshError)) options.onAuthRefreshError(keycloak);
29+
};
3030

31-
keycloak.onAuthLogout = function () {
32-
isFunction(options.onAuthLogout) && options.onAuthLogout(keycloak)
33-
}
31+
keycloak.onAuthLogout = () => {
32+
if (isFunction(options.onAuthLogout)) options.onAuthLogout(keycloak);
33+
};
3434

35-
keycloak.onTokenExpired = function () {
36-
isFunction(options.onTokenExpired) && options.onTokenExpired(keycloak)
37-
}
35+
keycloak.onTokenExpired = () => {
36+
if (isFunction(options.onTokenExpired)) options.onTokenExpired(keycloak);
37+
};
3838

3939
keycloak
4040
.init(options.init)
4141
.then((authenticated) => {
42-
isFunction(options.onInitSuccess) &&
43-
options.onInitSuccess(authenticated)
42+
if (isFunction(options.onInitSuccess)) options.onInitSuccess(authenticated);
4443
})
4544
.catch((error) => {
46-
isFunction(options.onInitError)
47-
? options.onInitError(error)
48-
: console.error(error)
49-
})
45+
if (isFunction(options.onInitError)) return options.onInitError(error);
46+
47+
// eslint-disable-next-line no-console
48+
return console.error(error);
49+
});
5050

51-
return keycloak
51+
return keycloak;
5252
}
5353

54-
let installed = false
54+
let installed = false;
5555

56-
export const Vuecloak = {
56+
const Vuecloak = {
5757
install: (app, options) => {
58-
if (installed) return
58+
if (installed) return;
5959

60-
installed = true
60+
installed = true;
6161

62-
const keycloak = init(options.config, options)
62+
const keycloak = init(options.config, options);
6363

64-
app.config.globalProperties.$keycloak = keycloak
65-
app.provide('$keycloak', keycloak)
64+
app.config.globalProperties.$keycloak = keycloak;
65+
app.provide('$keycloak', keycloak);
6666

67-
const IS_DEV = process.env.NODE_ENV === 'development'
68-
const IS_CLIENT = typeof window !== 'undefined'
67+
const IS_DEV = process.env.NODE_ENV === 'development';
68+
const IS_CLIENT = typeof window !== 'undefined';
6969

7070
if (IS_DEV && IS_CLIENT) {
71-
devtoolsPlugin(app, keycloak)
71+
devtoolsPlugin(app, keycloak);
7272
}
73-
}
74-
}
73+
},
74+
};
7575

76+
export { Vuecloak };
77+
export default Vuecloak;

0 commit comments

Comments
 (0)