Skip to content

Commit

Permalink
[frontend] Turn all current linting warnings into errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanAhlen committed Mar 11, 2024
1 parent b995721 commit 32b8bb2
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 82 deletions.
135 changes: 69 additions & 66 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,71 @@ const globals = normalGlobals.concat(hueGlobals).reduce((acc, key) => {
return acc;
}, {});

const jsTsVueRules = {
'no-useless-constructor': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-unused-vars': 'error',
'vue/max-attributes-per-line': [
'error',
{
singleline: 10,
multiline: {
max: 1,
allowFirstLine: false
}
}
],
'vue/html-self-closing': [
'error',
{
html: {
void: 'any'
}
}
],
'vue/singleline-html-element-content-newline': 'off' // Conflicts with prettier
};

const jestRules = {
'jest/no-focused-tests': 'error',
'jest/valid-expect': 'error',
'new-cap': 'off',
'no-console': 'off',
'no-restricted-syntax': [
'error',
{
selector:
'CallExpression[callee.object.name="console"][callee.property.name!=/^(warn|error|info|trace)$/]',
message: 'Unexpected property on console object was called'
}
],
'no-extra-boolean-cast': 'off',
'no-invalid-this': 'off',
'no-lonely-if': 'error',
'no-throw-literal': 'off',
'no-unused-vars': [
'error',
{
vars: 'all',
args: 'none',
ignoreRestSiblings: true,
varsIgnorePattern: '_[a-zA-Z0-9_]+'
}
],
'no-useless-constructor': 'error',
'no-var': 'error',
'no-undef': 'error',
'one-var': 'off',
'prefer-arrow-callback': 'error',
'prefer-const': ['warn', { destructuring: 'all' }],
'require-jsdoc': 'off',
strict: 'off',
'valid-jsdoc': 'off',
curly: ['error', 'all']
};

module.exports = {
env: {
browser: true,
Expand All @@ -76,47 +141,21 @@ module.exports = {
parser: '@typescript-eslint/parser'
},
plugins: ['vue', '@typescript-eslint'],
rules: {
'vue/max-attributes-per-line': [
'error',
{
singleline: 10,
multiline: {
max: 1,
allowFirstLine: false
}
}
],
'vue/html-self-closing': [
'error',
{
html: {
void: 'any'
}
}
],
'vue/singleline-html-element-content-newline': 0, // Conflicts with prettier
'@typescript-eslint/no-non-null-assertion': 0
}
rules: jsTsVueRules
},
{
files: ['*.d.ts'],
extends: ['plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['jest', '@typescript-eslint'],
rules: {
'no-useless-constructor': 0,
'@typescript-eslint/no-non-null-assertion': 0
}
rules: jsTsVueRules
},
{
files: ['*.ts', '*.tsx'],
extends: ['plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['jest', '@typescript-eslint'],
rules: {
'@typescript-eslint/no-non-null-assertion': 0
}
rules: jsTsVueRules
}
],
extends: ['plugin:prettier/recommended'],
Expand All @@ -131,42 +170,6 @@ module.exports = {
}
},
plugins: ['jest'],
rules: {
'jest/no-focused-tests': 'error',
'jest/valid-expect': 'error',
'new-cap': 0,
'no-console': 0,
'no-restricted-syntax': [
'error',
{
selector:
'CallExpression[callee.object.name="console"][callee.property.name!=/^(warn|error|info|trace)$/]',
message: 'Unexpected property on console object was called'
}
],
'no-extra-boolean-cast': 0,
'no-invalid-this': 0,
'no-lonely-if': 2,
'no-throw-literal': 0,
'no-unused-vars': [
'error',
{
vars: 'all',
args: 'none',
ignoreRestSiblings: true,
varsIgnorePattern: '_[a-zA-Z0-9_]+'
}
],
'no-useless-constructor': 2,
'no-var': 1,
'no-undef': 2,
'one-var': 0,
'prefer-arrow-callback': 2,
'prefer-const': ['warn', { destructuring: 'all' }],
'require-jsdoc': 0,
strict: 0,
'valid-jsdoc': 0,
curly: [2, 'all']
},
rules: jestRules,
settings: {}
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ const StorageBrowserTabContent: React.FC<StorageBrowserTabContentProps> = ({
const [files, setFiles] = useState<StorageBrowserTableData[]>();
const [loadingFiles, setloadingFiles] = useState(true);
const [pageStats, setPageStats] = useState<PageStats>();
const [pageSize, setPageSize] = useState<number>();
const [pageSize, setPageSize] = useState<number>(0);
const [pageNumber, setPageNumber] = useState<number>(1);
const [sortByColumn, setSortByColumn] = useState<string>('');
const [sortOrder, setSortOrder] = useState<SortOrder>(SortOrder.NONE);
//TODO: Add filter functionality
const [filterData, setFilterData] = useState<string>('');
const [filterData] = useState<string>('');

const { t } = i18nReact.useTranslation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ import Tooltip from 'antd/es/tooltip';

interface StorageBrowserTableProps {
className?: string;
dataSource: StorageBrowserTableData[];
dataSource?: StorageBrowserTableData[];
onFilepathChange: (path: string) => void;
onPageNumberChange: (pageNumber: number) => void;
onPageSizeChange: (pageSize: number) => void;
onSortByColumnChange: (sortByColumn: string) => void;
onSortOrderChange: (sortOrder: SortOrder) => void;
pageSize: number;
pageStats: PageStats;
pageStats?: PageStats;
sortByColumn: string;
sortOrder: SortOrder;
rowClassName?: string;
Expand Down Expand Up @@ -90,10 +90,10 @@ const StorageBrowserTable: React.FC<StorageBrowserTableProps> = ({
}
};

const getColumns = file => {
const columns: ColumnProps<unknown>[] = [];
const getColumns = (file: StorageBrowserTableData) => {
const columns: ColumnProps<StorageBrowserTableData>[] = [];
for (const [key] of Object.entries(file)) {
const column: ColumnProps<unknown> = {
const column: ColumnProps<StorageBrowserTableData> = {
dataIndex: key,
title: (
<div
Expand All @@ -117,7 +117,7 @@ const StorageBrowserTable: React.FC<StorageBrowserTableProps> = ({
if (key === 'name') {
column.width = '45%';
//TODO: Apply tooltip only for truncated values
column.render = (_, record: any) => (
column.render = (_, record: StorageBrowserTableData) => (
<Tooltip title={record.name}>
<span className="hue-storage-browser__table-cell-icon">
{record.type === 'dir' ? <FolderIcon /> : <FileOutlined />}
Expand All @@ -133,9 +133,9 @@ const StorageBrowserTable: React.FC<StorageBrowserTableProps> = ({
return columns.filter(col => col.dataIndex !== 'type' && col.dataIndex !== 'path');
};

const onRowClicked = record => {
const onRowClicked = (record: StorageBrowserTableData) => {
return {
onClick: e => {
onClick: () => {
if (record.type === 'dir') {
onFilepathChange(record.path);
}
Expand All @@ -145,12 +145,12 @@ const StorageBrowserTable: React.FC<StorageBrowserTableProps> = ({
};

//pagination related functions handled by parent
const onPreviousPageButtonClicked = previousPageNumber => {
const onPreviousPageButtonClicked = (previousPageNumber: number) => {
//If previous page does not exists api returns 0
onPageNumberChange(previousPageNumber === 0 ? 1 : previousPageNumber);
};

const onNextPageButtonClicked = (nextPageNumber, numPages) => {
const onNextPageButtonClicked = (nextPageNumber: number, numPages: number) => {
//If next page does not exists api returns 0
onPageNumberChange(nextPageNumber === 0 ? numPages : nextPageNumber);
};
Expand Down Expand Up @@ -178,7 +178,7 @@ const StorageBrowserTable: React.FC<StorageBrowserTableProps> = ({
};
}, []);

if (dataSource) {
if (dataSource && pageStats) {
return (
<>
<Table
Expand All @@ -203,6 +203,8 @@ const StorageBrowserTable: React.FC<StorageBrowserTableProps> = ({
/>
</>
);
} else {
return <div />;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Pagination: React.FC<PaginationProps> = ({
onPageSizeChange,
onPreviousPageButtonClicked,
pageSize,
pageSizeOptions,
pageSizeOptions = [],
pageStats
}): JSX.Element => {
const { t } = i18nReact.useTranslation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import React, { ReactNode, useState } from 'react';
import Joyride from 'react-joyride';

import { post } from 'api/utils';
import { hueWindow } from 'types/types';
import I18n from 'utils/i18n';
import { useHuePubSub } from '../useHuePubSub';
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"baseUrl": "desktop/core/src/desktop/js",
"typeRoots": [ "desktop/core/src/desktop/js/types", "./node_modules/@types"],
"lib": [
"es2019",
"es6",
"dom",
"webworker"
]
Expand Down

0 comments on commit 32b8bb2

Please sign in to comment.