eslint - rules updated
This commit is contained in:
@@ -5,38 +5,48 @@ module.exports = {
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
'no-null',
|
||||
'promise',
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:promise/recommended',
|
||||
],
|
||||
rules: {
|
||||
"no-console": "error",
|
||||
"max-len": ["error", {"code": 128}],
|
||||
"no-process-env": "error",
|
||||
"no-process-exit": "error",
|
||||
"no-null/no-null": "error",
|
||||
"no-useless-return": "error",
|
||||
"prefer-arrow-callback": "warn",
|
||||
"object-curly-spacing": "error",
|
||||
"consistent-return": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": [
|
||||
"error", {
|
||||
"allowExpressions": true,
|
||||
'max-len': ['error', {'code': 128}],
|
||||
'no-process-env': 'error',
|
||||
'no-process-exit': 'error',
|
||||
'no-null/no-null': 'error',
|
||||
'no-useless-return': 'error',
|
||||
'prefer-arrow-callback': 'warn',
|
||||
'consistent-return': 'error',
|
||||
'@typescript-eslint/explicit-function-return-type': [
|
||||
'error', {
|
||||
'allowExpressions': true,
|
||||
},
|
||||
],
|
||||
"no-void": "error",
|
||||
"comma-spacing": "error",
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
"comma-style": "error",
|
||||
"semi": "error",
|
||||
"no-implicit-coercion": "error",
|
||||
'no-void': 'error',
|
||||
'comma-spacing': 'error',
|
||||
'comma-dangle': ['error', 'always-multiline'],
|
||||
'comma-style': 'error',
|
||||
'semi': 'error',
|
||||
'no-implicit-coercion': 'error',
|
||||
'quotes': ['error', 'single', 'avoid-escape'],
|
||||
'keyword-spacing': 'error',
|
||||
'semi-spacing': 'error',
|
||||
'arrow-spacing': 'error',
|
||||
'object-curly-spacing': 'error',
|
||||
'array-bracket-spacing': 'error',
|
||||
'key-spacing': 'error',
|
||||
'block-spacing': 'error',
|
||||
'promise/always-return': 'off',
|
||||
|
||||
"no-restricted-imports": ["error",
|
||||
"assert", "buffer", "child_process", "cluster", "crypto", "dgram", "dns", "domain", "events", "freelist",
|
||||
"fs", "http", "https", "module", "net", "os", "path", "punycode", "querystring", "readline", "repl",
|
||||
"smalloc", "stream", "string_decoder", "sys", "timers", "tls", "tracing", "tty", "url", "util", "vm", "zlib",
|
||||
'no-restricted-imports': ['error',
|
||||
'assert', 'buffer', 'child_process', 'cluster', 'crypto', 'dgram', 'dns', 'domain', 'events', 'freelist',
|
||||
'fs', 'http', 'https', 'module', 'net', 'os', 'path', 'punycode', 'querystring', 'readline', 'repl',
|
||||
'smalloc', 'stream', 'string_decoder', 'sys', 'timers', 'tls', 'tracing', 'tty', 'url', 'util', 'vm', 'zlib',
|
||||
],
|
||||
'no-console': ['error', {allow: ['warn', 'error']}],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,6 +2,6 @@ import {getUserInfo} from './utils/utils';
|
||||
|
||||
export async function getUserName(): Promise<string> {
|
||||
const info = await getUserInfo();
|
||||
return info?.name ?? "No name found!";
|
||||
return info?.name ?? 'No name found!';
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import {getUserName} from './SomeModule';
|
||||
function updateUserName(name: string): void {
|
||||
const node = document.createElement('span');
|
||||
node.innerText = `This user name is fetched with Javascript: ${name}`;
|
||||
document.getElementsByTagName("body")[0].appendChild(node);
|
||||
document.getElementsByTagName('body')[0].appendChild(node);
|
||||
}
|
||||
|
||||
getUserName().then(updateUserName);
|
||||
getUserName().then(updateUserName).catch((err) => console.error(err));
|
||||
|
||||
@@ -22,7 +22,7 @@ export function resetConfig(): void {
|
||||
|
||||
export async function getUserInfo(): Promise<Partial<UserInfo>|undefined> {
|
||||
const config = await getConfig();
|
||||
const res = await fetch(config.EXTERNAL_BASE_URL + "/api/user");
|
||||
const res = await fetch(config.EXTERNAL_BASE_URL + '/api/user');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import {getUserName} from '../src/SomeModule';
|
||||
import {setConfig, UserInfo} from '../src/utils/utils';
|
||||
|
||||
describe('frontend:SomeModule', () => {
|
||||
const CONFIG = {EXTERNAL_BASE_URL: "http://demo.url"};
|
||||
const CONFIG = {EXTERNAL_BASE_URL: 'http://demo.url'};
|
||||
before(() => {
|
||||
setConfig(CONFIG);
|
||||
fetchMock.config.overwriteRoutes = true;
|
||||
@@ -15,14 +15,14 @@ describe('frontend:SomeModule', () => {
|
||||
it('should return username', async () => {
|
||||
const tests: [Partial<UserInfo>, string][] = [
|
||||
[
|
||||
{name: "John Doe"},
|
||||
"John Doe",
|
||||
{name: 'John Doe'},
|
||||
'John Doe',
|
||||
], [
|
||||
{name: "John Doe", email: "some.mail@example.com"},
|
||||
"John Doe",
|
||||
{name: 'John Doe', email: 'some.mail@example.com'},
|
||||
'John Doe',
|
||||
], [
|
||||
{name: "", email: "some.mail@example.com"},
|
||||
"",
|
||||
{name: '', email: 'some.mail@example.com'},
|
||||
'',
|
||||
],
|
||||
];
|
||||
for (const [USER_INFO, RESULT] of tests) {
|
||||
@@ -35,13 +35,13 @@ describe('frontend:SomeModule', () => {
|
||||
}
|
||||
});
|
||||
it('should return default string', async () => {
|
||||
const RESULT = "No name found!";
|
||||
const RESULT = 'No name found!';
|
||||
const tests: (Partial<UserInfo>|unknown)[] = [
|
||||
// eslint-disable-next-line no-null/no-null
|
||||
{name: null},
|
||||
// eslint-disable-next-line no-null/no-null
|
||||
null,
|
||||
{email: "some.mail@example.com"},
|
||||
{email: 'some.mail@example.com'},
|
||||
{name: undefined},
|
||||
{},
|
||||
];
|
||||
|
||||
@@ -7,13 +7,13 @@ import {JSDOM} from 'jsdom';
|
||||
// @ts-ignore
|
||||
import * as rewire from 'rewire';
|
||||
|
||||
describe("frontend:index", () => {
|
||||
const updateUserName = rewire("../src/index").__get__("updateUserName") as (name: string) => void;
|
||||
describe('frontend:index', () => {
|
||||
const updateUserName = rewire('../src/index').__get__('updateUserName') as (name: string) => void;
|
||||
|
||||
beforeEach(() => {
|
||||
const dom = new JSDOM(
|
||||
`
|
||||
<html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -27,13 +27,13 @@ describe("frontend:index", () => {
|
||||
global.document = dom.window.document;
|
||||
});
|
||||
|
||||
it("updateUserName", (done) => {
|
||||
const NAME = "Patrick Star";
|
||||
const RESULT = "This user name is fetched with Javascript: Patrick Star";
|
||||
it('updateUserName', (done) => {
|
||||
const NAME = 'Patrick Star';
|
||||
const RESULT = 'This user name is fetched with Javascript: Patrick Star';
|
||||
updateUserName(NAME);
|
||||
// give the browser a chance to update the DOM
|
||||
setTimeout(() => {
|
||||
const span = document.getElementsByTagName("span");
|
||||
const span = document.getElementsByTagName('span');
|
||||
expect(span).to.not.be.null;
|
||||
expect(span.length).to.be.greaterThan(0);
|
||||
expect(span[0].innerText).to.deep.equal(RESULT);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable promise/catch-or-return,promise/no-callback-in-promise */
|
||||
import {setConfig, getConfig, resetConfig, getUserInfo, UserInfo} from '../src/utils/utils';
|
||||
import {Resolvable, WaitForSync} from '../src/utils/resolvable';
|
||||
import {describe, it} from 'mocha';
|
||||
@@ -7,7 +8,7 @@ import {expect} from 'chai';
|
||||
import * as fetchMock from 'fetch-mock';
|
||||
|
||||
describe('frontend:utils - setConfig/getConfig', () => {
|
||||
const CONFIG = {EXTERNAL_BASE_URL: "http://demo.url"};
|
||||
const CONFIG = {EXTERNAL_BASE_URL: 'http://demo.url'};
|
||||
afterEach(() => resetConfig());
|
||||
|
||||
it('should return config (afterwards)', async () => {
|
||||
@@ -25,9 +26,9 @@ describe('frontend:utils - setConfig/getConfig', () => {
|
||||
});
|
||||
|
||||
describe('frontend:utils - getUserInfo', () => {
|
||||
const CONFIG = {EXTERNAL_BASE_URL: "http://demo.url"};
|
||||
const CONFIG = {EXTERNAL_BASE_URL: 'http://demo.url'};
|
||||
const USER_INFO: Partial<UserInfo> = {
|
||||
name: "John Doe",
|
||||
name: 'John Doe',
|
||||
};
|
||||
|
||||
beforeEach(() => setConfig(CONFIG));
|
||||
@@ -46,7 +47,7 @@ describe('frontend:utils - getUserInfo', () => {
|
||||
|
||||
describe('frontend:utils - resolvable', () => {
|
||||
const DATA = 5;
|
||||
const ERROR = new Error("Custom error!");
|
||||
const ERROR = new Error('Custom error!');
|
||||
|
||||
it('waitForSync should return data (afterwards)', async () => {
|
||||
const resolvable = new WaitForSync<number>();
|
||||
|
||||
Reference in New Issue
Block a user