Phase 10: запрет inline eslint-disable, file-level overrides, IUser-тип
This commit is contained in:
+42
-7
@@ -18,6 +18,8 @@ const CONFIG_ROOT = import.meta.dirname;
|
||||
const TEST_FILES = ['**/*.{test,spec}.{ts,tsx}'];
|
||||
const CONFIG_AND_SCRIPT_FILES = ['**/*.config.{ts,mts,cts}', '**/vite.config.*'];
|
||||
|
||||
/* eslint-disable no-unused-vars -- eslint.config.js lintится самим собой */
|
||||
|
||||
/* Забираем правила из пресетов плагинов */
|
||||
const reactRecommendedRules =
|
||||
react.configs.flat?.recommended?.rules ??
|
||||
@@ -50,8 +52,11 @@ export default defineConfig(
|
||||
{
|
||||
name: 'client/linter-policy',
|
||||
linterOptions: {
|
||||
noInlineConfig: false,
|
||||
// Inline-директивы (eslint-disable и т.п.) в коде запрещены.
|
||||
// Единственный способ отключить правило — file-level override в этом конфиге.
|
||||
noInlineConfig: true,
|
||||
reportUnusedDisableDirectives: 'error',
|
||||
reportUnusedInlineConfigs: 'error',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -274,12 +279,6 @@ export default defineConfig(
|
||||
'newlines-between': 'always',
|
||||
}],
|
||||
|
||||
/* Запрет необъяснённых disable-директив */
|
||||
'@eslint-community/eslint-comments/disable-enable-pair': ['error', { allowWholeFile: false }],
|
||||
'@eslint-community/eslint-comments/no-aggregating-enable': 'error',
|
||||
'@eslint-community/eslint-comments/no-duplicate-disable': 'error',
|
||||
'@eslint-community/eslint-comments/no-unlimited-disable': 'error',
|
||||
'@eslint-community/eslint-comments/require-description': ['error', { ignore: ['eslint-enable'] }],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -310,4 +309,40 @@ export default defineConfig(
|
||||
'@typescript-eslint/require-await': 'off',
|
||||
},
|
||||
},
|
||||
|
||||
/* ── Файловые исключения (единственный способ отключить правило) ── */
|
||||
{
|
||||
name: 'client/api-client',
|
||||
files: ['src/api/client.ts'],
|
||||
rules: {
|
||||
// fetch.json() возвращает any — assertion неизбежен
|
||||
'@typescript-eslint/no-unsafe-type-assertion': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'client/news-editor',
|
||||
files: ['src/hooks/useNewsEditor.ts'],
|
||||
rules: {
|
||||
// Хук-оркестратор: 4 action-обработчика + toolbar + upload
|
||||
'max-lines-per-function': 'off',
|
||||
// window.confirm для подтверждения удаления
|
||||
'no-alert': 'off',
|
||||
// e.target.value = '' — сброс file input (стандартный паттерн)
|
||||
'no-param-reassign': ['error', { props: true, ignorePropertyModificationsFor: ['e'] }],
|
||||
// Навигация после await (window.location.href → useNavigate)
|
||||
'require-atomic-updates': 'off',
|
||||
// async IIFE в useEffect для загрузки новости
|
||||
'@typescript-eslint/no-floating-promises': 'off',
|
||||
// newsId гарантированно string (проверено isNew)
|
||||
'@typescript-eslint/restrict-template-expressions': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'client/auth-pages',
|
||||
files: ['src/pages/LoginPage.tsx', 'src/pages/RegisterPage.tsx'],
|
||||
rules: {
|
||||
// .then()/.catch() в цепочке — не floating promise
|
||||
'@typescript-eslint/no-floating-promises': 'off',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -80,7 +80,6 @@ async function handleResponse<T>(res: Response): Promise<T> {
|
||||
window.location.href = '/login';
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- fetch.json() returns any
|
||||
const data = (await res.json().catch(() => ({}))) as unknown as ApiErrorBody & T;
|
||||
|
||||
if (!res.ok) {
|
||||
|
||||
@@ -17,10 +17,8 @@ function useLoadNews(newsId: string | undefined, isNew: boolean) {
|
||||
if (isNew) {
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- async IIFE в useEffect
|
||||
void (async () => {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- newsId гарантированно string (проверено isNew)
|
||||
const data = await apiFetch<{ news: { title: string; content: string; status: string } }>(`/news/${newsId}`);
|
||||
setTitle(data.news.title);
|
||||
setContent(data.news.content);
|
||||
@@ -45,7 +43,6 @@ function useLoadNews(newsId: string | undefined, isNew: boolean) {
|
||||
* @param newsId — id новости или undefined для создания
|
||||
* @returns состояние и обработчики для NewsEditorPage
|
||||
*/
|
||||
/* eslint-disable max-lines-per-function -- хук-оркестратор */
|
||||
export function useNewsEditor(newsId: string | undefined) {
|
||||
const isNew = newsId === undefined;
|
||||
const { title, setTitle, content, setContent, newsStatus, loading } = useLoadNews(newsId, isNew);
|
||||
@@ -149,7 +146,6 @@ export function useNewsEditor(newsId: string | undefined) {
|
||||
if (newsId === undefined) {
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-alert -- подтверждение удаления
|
||||
if (!window.confirm('Удалить новость?')) {
|
||||
return;
|
||||
}
|
||||
@@ -157,7 +153,6 @@ export function useNewsEditor(newsId: string | undefined) {
|
||||
setError('');
|
||||
try {
|
||||
await apiFetch(`/news/${newsId}`, { method: 'DELETE' });
|
||||
// eslint-disable-next-line require-atomic-updates -- navigation after await
|
||||
window.location.href = '/news';
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Ошибка удаления');
|
||||
@@ -214,7 +209,6 @@ export function useNewsEditor(newsId: string | undefined) {
|
||||
if (file !== undefined) {
|
||||
handleFileUpload(file, true).catch((err: unknown) => { console.error(err); });
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign -- сброс file input
|
||||
e.target.value = '';
|
||||
}, [handleFileUpload]);
|
||||
|
||||
@@ -224,7 +218,6 @@ export function useNewsEditor(newsId: string | undefined) {
|
||||
if (file !== undefined) {
|
||||
handleFileUpload(file, false).catch((err: unknown) => { console.error(err); });
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign -- сброс file input
|
||||
e.target.value = '';
|
||||
}, [handleFileUpload]);
|
||||
|
||||
@@ -239,4 +232,3 @@ export function useNewsEditor(newsId: string | undefined) {
|
||||
onSave, onPublish, onDelete, onSchedule,
|
||||
};
|
||||
}
|
||||
/* eslint-enable max-lines-per-function */
|
||||
|
||||
@@ -16,7 +16,6 @@ export function LoginPage() {
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises -- Promise обработан через .catch() */
|
||||
const handleSubmit = (e: FormEvent): void => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
@@ -28,7 +27,6 @@ export function LoginPage() {
|
||||
})
|
||||
.finally(() => { setLoading(false); });
|
||||
};
|
||||
/* eslint-enable @typescript-eslint/no-floating-promises */
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
|
||||
@@ -17,7 +17,6 @@ export function NewsListPage() {
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- async IIFE в useEffect
|
||||
void (async () => {
|
||||
try {
|
||||
const data = await apiFetch<{ news: NewsItem[] }>('/news');
|
||||
|
||||
@@ -17,7 +17,6 @@ export function RegisterPage() {
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises -- Promise обработан через .catch() */
|
||||
const handleSubmit = (e: FormEvent): void => {
|
||||
e.preventDefault();
|
||||
if (password !== confirmPassword) {
|
||||
@@ -33,7 +32,6 @@ export function RegisterPage() {
|
||||
})
|
||||
.finally(() => { setLoading(false); });
|
||||
};
|
||||
/* eslint-enable @typescript-eslint/no-floating-promises */
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
|
||||
Reference in New Issue
Block a user