Skip to content

Commit

Permalink
chore(eslint): enable strict rule set form @typescript-eslint
Browse files Browse the repository at this point in the history
- fix linter errors
- remove no-type-assertion plugin
  • Loading branch information
SimonGolms committed Jan 16, 2023
1 parent 6c1b0b2 commit f02d44c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 7 deletions.
45 changes: 42 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ module.exports = {
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/strict',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:jest/all',
Expand All @@ -15,24 +18,52 @@ module.exports = {
// HINT: prettier must be the last extension to work
'prettier',
],
ignorePatterns: ['coverage', 'lib', 'node_modules'],
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'no-undef': 'off',
'no-unused-vars': 'off',
},
},
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: ['./tsconfig.eslint.json'],
tsconfigRootDir: __dirname,
},
plugins: [
'@typescript-eslint',
'jest',
'sonarjs',
'sort-keys-fix',
'typescript-sort-keys',
'no-type-assertion',
// HINT: prettier must be the last plugin to work
'prettier',
],
rules: {
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
'@typescript-eslint/no-misused-promises': [
'error',
{
checksVoidReturn: false,
},
],
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/sort-type-union-intersection-members': 'error',
camelcase: 'warn',
curly: 'error',
'import/no-cycle': 'error',
'import/no-unused-modules': [
'error',
{
Expand All @@ -52,7 +83,6 @@ module.exports = {
caseInsensitive: true,
order: 'asc',
},
groups: ['builtin', 'external', 'internal'],
},
],
'import/prefer-default-export': 'off',
Expand All @@ -70,6 +100,15 @@ module.exports = {
'prefer-const': 'error',
'prettier/prettier': 'error',
semi: 'error',
'sort-imports': [
'error',
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
},
],
// Required to fix sort-keys automatically, since this is not done by default.
'sort-keys-fix/sort-keys-fix': [
'error',
'asc',
Expand Down
2 changes: 1 addition & 1 deletion src/commands/tag/tag.utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { composeTag } from './tag.utils';

describe('composeTag', () => {
test('get Setup Uri for switch', async () => {
test('get Setup Uri for switch', () => {
expect.assertions(1);
const tag = composeTag('84131633');

Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@

import { createQrCode } from './commands/qrcode/qrcode';
import { createTag } from './commands/tag/tag';
import { isValidCategory } from './utils/isValidCategory';
import { argv } from './yargs';

const main = async () => {
const { _: commands, name, output, pairingCode, zoom } = argv;

if (commands[0] === 'qrcode') {
const { category, flag, setupId = '' } = argv;
await createQrCode({ category, flag, name, output, pairingCode, setupId, zoom });
// Type-Guard since yargs does not support custom types that well
if (isValidCategory(category)) {
await createQrCode({ category, flag, name, output, pairingCode, setupId, zoom });
}
}
if (commands[0] === 'tag') {
await createTag({ name, output, pairingCode, zoom });
}
};

main();
void main();
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { OUTPUT_FORMATS } from '../config/output';

export type Category = keyof typeof CATEGORIES;

// eslint-disable-next-line prettier/prettier
export type OutputFormat = typeof OUTPUT_FORMATS[number];

export type CreateFileBuffer = CreateImage & {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/image.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Resvg } from '@resvg/resvg-js';
import { CreateImage } from '../types';

export const createImage = async ({ svg, zoom = 5 }: CreateImage): Promise<Buffer> => {
export const createImage = ({ svg, zoom = 5 }: CreateImage) => {
const resvg = new Resvg(svg, {
fitTo: {
mode: 'zoom',
Expand Down
6 changes: 6 additions & 0 deletions src/utils/isValidCategory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { CATEGORIES } from '../config/categories';
import { Category } from '../types';

export const isValidCategory = (category: unknown): category is Category => {
return typeof category === 'string' && Object.keys(CATEGORIES).includes(category);
};
7 changes: 7 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"rootDir": "."
},
"extends": "./tsconfig.json",
"include": [".", "./.eslintrc.js", "./jest.config.ts"]
}

0 comments on commit f02d44c

Please sign in to comment.