eslint - rules updated

This commit is contained in:
Sebastian Seedorf
2020-11-19 22:22:14 +01:00
parent b79c2f96cd
commit 5c31dc285a
13 changed files with 100 additions and 83 deletions

View File

@@ -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']}],
},
};

View File

@@ -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!';
}

View File

@@ -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));

View File

@@ -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();
}

View File

@@ -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},
{},
];

View File

@@ -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);

View File

@@ -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>();

View File

@@ -9,32 +9,38 @@ module.exports = {
],
extends: [
'eslint:recommended',
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:promise/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,
'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',
'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",
"promise/always-return": "off",
'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',
},
};

View File

@@ -11,11 +11,11 @@ export const app = express();
// Permissions
PermManager
.grant("user")
.execute("read").on("userinfo")
.grant("coe_bs")
.extend("user")
.execute("write").on("userinfo");
.grant('user')
.execute('read').on('userinfo')
.grant('coe_bs')
.extend('user')
.execute('write').on('userinfo');
// view engine setup
app.set('views', path.join(__dirname, '../views'));
@@ -44,7 +44,7 @@ router.use(AutoReloader.router);
//router.use(Session.getRouter());
// static config
router.use("/js/polyfill.js", Polyfill.getRouter('./public/js/bundle.js'));
router.use('/js/polyfill.js', Polyfill.getRouter('./public/js/bundle.js'));
router.use(sassMiddleware({
src: path.join(__dirname, '../public'),
dest: path.join(__dirname, '../public'),

View File

@@ -1,5 +1,5 @@
/* eslint-disable no-process-exit,no-console */
import * as http from "http";
import * as http from 'http';
import {DefaultConfig, urlJoin} from 'pkg-express-utils';
const options = {

View File

@@ -9,9 +9,9 @@ import {DefaultConfig, Logger} from 'pkg-express-utils';
app.set('port', DefaultConfig.PORT);
const server = http.createServer(app);
app.listen(DefaultConfig.PORT);
server.on('error', onError);
server.on('listening', onListening);
server.listen(DefaultConfig.PORT);
function onError(error: HttpError): void {
if (error.syscall !== 'listen') {

View File

@@ -4,7 +4,7 @@ import {PermManager} from 'pkg-express-utils';
const userRouter = express.Router();
/* GET users listing. */
userRouter.get('/', PermManager.getRouter("userinfo", {action: "read"}), async (req, res) => {
userRouter.get('/', PermManager.getRouter('userinfo', {action: 'read'}), async (req, res) => {
res.json(await req.getUserInfo() || {});
});

View File

@@ -5,12 +5,12 @@ import healthRouter from './healthcheck';
const router = express.Router();
export default router;
router.use("/api/user", userRouter);
router.use("/health", healthRouter);
router.use('/api/user', userRouter);
router.use('/health', healthRouter);
/* GET home page. */
router.get('/', async (req, res) => {
const email = (await req.getUserInfo())?.email ?? "No email found!";
const email = (await req.getUserInfo())?.email ?? 'No email found!';
res.render('index', {title: 'Express', email});
});