Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eslint and "lint" npm scripts #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions packages/client/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/* eslint-env node */
module.exports = {
'env': {
'browser': true,
'commonjs': true,
'es6': true
},
'extends': ['eslint:recommended', 'plugin:prettier/recommended'],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module'
},
'rules': {
'accessor-pairs': 'error',
'array-callback-return': 'error',
'block-scoped-var': 'error',
'callback-return': 'error',
'class-methods-use-this': 'error',
'complexity': 'error',
'consistent-return': [
'error',
{
'treatUndefinedAsUnspecified': false
}
],
'curly': 'error',
'default-case': 'error',
'default-param-last': 'error',
'dot-location': [
'error',
'property'
],
'dot-notation': 'error',
'eqeqeq': 'error',
'global-require': 'off',
'guard-for-in': 'error',
'handle-callback-err': 'error',
'indent-legacy': 'error',
'init-declarations': 'off',
'lines-around-directive': 'error',
'max-classes-per-file': 'error',
'newline-after-var': 'off',
'newline-before-return': 'off',
'no-alert': 'error',
'no-await-in-loop': 'error',
'no-buffer-constructor': 'error',
'no-caller': 'error',
'no-catch-shadow': 'error',
'no-confusing-arrow': 'error',
'no-console': 'error',
'no-div-regex': 'error',
'no-duplicate-imports': 'error',
'no-else-return': 'error',
'no-empty-function': 'error',
'no-eq-null': 'error',
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-extra-label': 'error',
'no-extra-parens': 'error',
'no-floating-decimal': 'error',
'no-implicit-globals': 'error',
'no-implied-eval': 'error',
'no-import-assign': 'error',
'no-invalid-this': 'error',
'no-iterator': 'error',
'no-label-var': 'error',
'no-labels': 'error',
'no-lone-blocks': 'error',
'no-loop-func': 'error',
'no-magic-numbers': 'off',
'no-mixed-requires': 'error',
'no-multi-spaces': 'error',
'no-multi-str': 'error',
'no-negated-in-lhs': 'error',
'no-new': 'error',
'no-new-func': 'error',
'no-new-require': 'error',
'no-new-wrappers': 'error',
'no-octal-escape': 'error',
'no-param-reassign': 'off',
'no-path-concat': 'error',
'no-process-env': 'error',
'no-process-exit': 'error',
'no-proto': 'error',
'no-restricted-globals': 'error',
'no-restricted-imports': 'error',
'no-restricted-modules': 'error',
'no-restricted-properties': 'error',
'no-return-assign': 'error',
'no-return-await': 'error',
'no-script-url': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-shadow': 'error',
'no-spaced-func': 'error',
'no-sync': 'error',
'no-template-curly-in-string': 'error',
'no-throw-literal': 'error',
'no-undef-init': 'error',
'no-undefined': 'off',
'no-unmodified-loop-condition': 'error',
'no-unused-expressions': 'error',
'no-use-before-define': 'off',
'no-useless-call': 'error',
'no-useless-computed-key': 'error',
'no-useless-concat': 'error',
'no-useless-constructor': 'error',
'no-useless-rename': 'error',
'no-useless-return': 'error',
'no-var': 'error',
'no-void': 'error',
'no-warning-comments': 'off',
'nonblock-statement-body-position': 'error',
'object-shorthand': 'error',
'prefer-arrow-callback': 'error',
'prefer-const': 'error',
'prefer-destructuring': 'off',
'prefer-named-capture-group': 'off',
'prefer-numeric-literals': 'error',
'prefer-promise-reject-errors': 'error',
'prefer-reflect': 'error',
'prefer-regex-literals': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'off',
'radix': 'error',
'require-await': 'off',
'require-jsdoc': 'off',
'require-unicode-regexp': 'off',
'sort-imports': 'error',
'strict': [
'error',
'never'
],
'symbol-description': 'error',
'template-curly-spacing': [
'error',
'never'
],
'valid-jsdoc': 'off',
'vars-on-top': 'error',
'wrap-iife': 'error',
'yoda': [
'error',
'never'
]
}
};
4 changes: 4 additions & 0 deletions packages/client/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"tabWidth": 4
}
5 changes: 5 additions & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"scripts": {
"build": "webpack --mode=production",
"lint": "eslint --fix --ignore-pattern !.eslintrc.js src",
"prepublish": "webpack --mode=production"
},
"license": "Apache-2.0",
Expand All @@ -23,6 +24,10 @@
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-loader": "^8.0.6",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-prettier": "^3.1.1",
"prettier": "^1.19.1",
"webpack-cli": "^3.3.1"
}
}
10 changes: 5 additions & 5 deletions packages/client/src/solveLoginChallenge.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import  { publicKeyCredentialToJSON } from './utils';
import { publicKeyCredentialToJSON } from './utils';

const loginChallengeToPublicKey = getAssert => {
const { Unibabel } = require('unibabel');
Expand All @@ -8,8 +8,8 @@ const loginChallengeToPublicKey = getAssert => {
challenge: Unibabel.base64ToBuffer(getAssert.challenge),
allowCredentials: getAssert.allowCredentials.map(allowCredential => ({
...allowCredential,
id: Unibabel.base64ToBuffer(allowCredential.id),
})),
id: Unibabel.base64ToBuffer(allowCredential.id)
}))
};
};

Expand All @@ -18,8 +18,8 @@ export const solveLoginChallenge = async credentialsChallengeRequest => {

// @ts-ignore
const credentials = await navigator.credentials.get({
publicKey,
publicKey
});

return publicKeyCredentialToJSON(credentials);
};
};
8 changes: 4 additions & 4 deletions packages/client/src/solveRegistrationChallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const registrationChallengeToPublicKey = credentialsChallengeRequest => {
),
user: {
...credentialsChallengeRequest.user,
id: Unibabel.base64ToBuffer(credentialsChallengeRequest.user.id),
},
id: Unibabel.base64ToBuffer(credentialsChallengeRequest.user.id)
}
};
};

Expand All @@ -20,8 +20,8 @@ export const solveRegistrationChallenge = async credentialsChallengeRequest => {
credentialsChallengeRequest
);
const credentials = await navigator.credentials.create({
publicKey,
publicKey
});

return publicKeyCredentialToJSON(credentials);
};
};
8 changes: 3 additions & 5 deletions packages/client/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export const publicKeyCredentialToJSON = (
item
) => {
export const publicKeyCredentialToJSON = item => {
if (item instanceof Array) {
return item.map(publicKeyCredentialToJSON);
}
Expand All @@ -14,7 +12,7 @@ export const publicKeyCredentialToJSON = (
if (item instanceof Object) {
const obj = {};

// tslint:disable-next-line
// eslint-disable-next-line guard-for-in
for (const key in item) {
obj[key] = publicKeyCredentialToJSON(item[key]);
}
Expand All @@ -23,4 +21,4 @@ export const publicKeyCredentialToJSON = (
}

return item;
};
};
46 changes: 26 additions & 20 deletions packages/client/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
/* eslint-env node */
module.exports = [
{
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { useBuiltIns: 'usage', corejs: 3 }]]
}
}
{
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env', { useBuiltIns: 'usage',
corejs: 3 }
]
]
}
}
}
]
},
output: {
filename: 'main.js',
libraryTarget: 'umd',
globalObject: 'this'
}
]
},
output: {
filename: 'main.js',
libraryTarget: 'umd',
globalObject: 'this'
}
}
]
];
Loading