mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 11:43:59 -05:00
ESLint: Enable @typescript-eslint/naming-convention rule
This check enforces consistent variable naming. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
c3129d40e0
commit
3626ce9dff
4 changed files with 32 additions and 6 deletions
24
.eslintrc.js
24
.eslintrc.js
|
@ -28,5 +28,29 @@ module.exports = {
|
||||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||||
'no-return-await': 'off',
|
'no-return-await': 'off',
|
||||||
'@typescript-eslint/return-await': ['error', 'always'],
|
'@typescript-eslint/return-await': ['error', 'always'],
|
||||||
|
'@typescript-eslint/naming-convention': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
selector: 'default',
|
||||||
|
format: ['camelCase'],
|
||||||
|
leadingUnderscore: 'allow',
|
||||||
|
trailingUnderscore: 'allow',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
selector: 'enumMember',
|
||||||
|
format: ['UPPER_CASE'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
selector: 'variable',
|
||||||
|
format: ['camelCase', 'UPPER_CASE'],
|
||||||
|
leadingUnderscore: 'allow',
|
||||||
|
trailingUnderscore: 'allow',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
selector: 'typeLike',
|
||||||
|
format: ['PascalCase'],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,8 @@ import * as getRawBody from 'raw-body';
|
||||||
*
|
*
|
||||||
* Implementation inspired by https://stackoverflow.com/questions/52283713/how-do-i-pass-plain-text-as-my-request-body-using-nestjs
|
* Implementation inspired by https://stackoverflow.com/questions/52283713/how-do-i-pass-plain-text-as-my-request-body-using-nestjs
|
||||||
*/
|
*/
|
||||||
|
// Override naming convention as decorators are in PascalCase
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
export const MarkdownBody = createParamDecorator(
|
export const MarkdownBody = createParamDecorator(
|
||||||
async (_, context: ExecutionContext) => {
|
async (_, context: ExecutionContext) => {
|
||||||
// we have to check req.readable because of raw-body issue #57
|
// we have to check req.readable because of raw-body issue #57
|
||||||
|
|
|
@ -69,7 +69,7 @@ describe('AuthService', () => {
|
||||||
.then((result) => expect(result).toBeTruthy());
|
.then((result) => expect(result).toBeTruthy());
|
||||||
});
|
});
|
||||||
it('fails, if secret is too short', async () => {
|
it('fails, if secret is too short', async () => {
|
||||||
const secret = service.BufferToBase64Url(await service.randomString(54));
|
const secret = service.bufferToBase64Url(await service.randomString(54));
|
||||||
const hash = await service.hashPassword(secret);
|
const hash = await service.hashPassword(secret);
|
||||||
service
|
service
|
||||||
.checkPassword(secret, hash)
|
.checkPassword(secret, hash)
|
||||||
|
@ -277,10 +277,10 @@ describe('AuthService', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BufferToBase64Url', () => {
|
describe('bufferToBase64Url', () => {
|
||||||
it('works', () => {
|
it('works', () => {
|
||||||
expect(
|
expect(
|
||||||
service.BufferToBase64Url(
|
service.bufferToBase64Url(
|
||||||
Buffer.from('testsentence is a test sentence'),
|
Buffer.from('testsentence is a test sentence'),
|
||||||
),
|
),
|
||||||
).toEqual('dGVzdHNlbnRlbmNlIGlzIGEgdGVzdCBzZW50ZW5jZQ');
|
).toEqual('dGVzdHNlbnRlbmNlIGlzIGEgdGVzdCBzZW50ZW5jZQ');
|
||||||
|
|
|
@ -69,7 +69,7 @@ export class AuthService {
|
||||||
return randomBytes(length);
|
return randomBytes(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferToBase64Url(text: Buffer): string {
|
bufferToBase64Url(text: Buffer): string {
|
||||||
// This is necessary as the is no base64url encoding in the toString method
|
// This is necessary as the is no base64url encoding in the toString method
|
||||||
// but as can be seen on https://tools.ietf.org/html/rfc4648#page-7
|
// but as can be seen on https://tools.ietf.org/html/rfc4648#page-7
|
||||||
// base64url is quite easy buildable from base64
|
// base64url is quite easy buildable from base64
|
||||||
|
@ -93,8 +93,8 @@ export class AuthService {
|
||||||
`User '${user.userName}' has already 200 tokens and can't have anymore`,
|
`User '${user.userName}' has already 200 tokens and can't have anymore`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const secret = this.BufferToBase64Url(await this.randomString(54));
|
const secret = this.bufferToBase64Url(await this.randomString(54));
|
||||||
const keyId = this.BufferToBase64Url(await this.randomString(8));
|
const keyId = this.bufferToBase64Url(await this.randomString(8));
|
||||||
const accessToken = await this.hashPassword(secret);
|
const accessToken = await this.hashPassword(secret);
|
||||||
let token;
|
let token;
|
||||||
// Tokens can only be valid for a maximum of 2 years
|
// Tokens can only be valid for a maximum of 2 years
|
||||||
|
|
Loading…
Reference in a new issue