summaryrefslogtreecommitdiffstats
path: root/eslint.config.mjs
blob: 36ba7881080d58dc7e927eb5245e18caed44511e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { defineConfig, globalIgnores } from 'eslint/config';
import globals from 'globals';
import markdown from "@eslint/markdown";
import jsdoc from 'eslint-plugin-jsdoc';
import json from '@eslint/json';
import js from '@eslint/js';

console.log("loaded luci repo eslint.config.mjs");

export const jsdoc_less_relaxed_rules = {
 	// 0: off, 1: warn, 2: error
	/* --- JSDoc correctness --- */
	'jsdoc/check-alignment': 'warn',
	'jsdoc/check-param-names': 'off',
	'jsdoc/check-tag-names': 'warn',
	'jsdoc/check-types': 'off',
	'jsdoc/no-defaults': 'off',
	'jsdoc/reject-any-type': 'off',
	'jsdoc/require-jsdoc': 'off',
	'jsdoc/require-param': 'warn',
	'jsdoc/require-returns': 'warn',
	'jsdoc/require-returns-check': 'off',
	'jsdoc/require-returns-type': 'warn',
	'jsdoc/tag-lines': 'off',
	'no-shadow-restricted-names': 'off',

	/* --- Style --- */
	'jsdoc/require-description': 'off',
	'jsdoc/require-param-description': 'off',
	'jsdoc/require-returns-description': 'off',

	/* --- custom classes and types --- */
	'jsdoc/no-undefined-types': 'warn', // custom LuCI types
	'jsdoc/valid-types': 'warn',
}

export const jsdoc_relaxed_rules = {
 	// 0: off, 1: warn, 2: error
	/* --- JSDoc correctness --- */
	'jsdoc/check-alignment': 'warn',
	'jsdoc/check-param-names': 'off',
	'jsdoc/check-tag-names': 'warn',
	'jsdoc/check-types': 'off',
	'jsdoc/no-defaults': 'off',
	'jsdoc/reject-any-type': 'off',
	'jsdoc/require-jsdoc': 'off',
	'jsdoc/require-param': 'warn',
	'jsdoc/require-returns': 'warn',
	'jsdoc/require-returns-check': 'off',
	'jsdoc/require-returns-type': 'warn',
	'jsdoc/tag-lines': 'off',
	'no-shadow-restricted-names': 'off',

	/* --- Style --- */
	'jsdoc/require-description': 'off',
	'jsdoc/require-param-description': 'off',
	'jsdoc/require-returns-description': 'off',

	/* --- custom classes and types --- */
	'jsdoc/no-undefined-types': 'off', // custom LuCI types
	'jsdoc/valid-types': 'off',
}

export default defineConfig([
	globalIgnores([
		'docs',
		'node_modules',
	]),
	// Markdown
	{
		files: ["**/*.md"],
		plugins: {
			markdown,
		},
		processor: "markdown/markdown",
	},
	// applies only to JavaScript blocks inside of Markdown files
	{
		files: ["**/*.md/*.js"],
		rules: {
			strict: "off",
		},
	},
	// JSON files
	{
		files: ['**/*.json'],
		ignores: ['package-lock.json'],
		plugins: { json },
		language: 'json/json',
		extends: ['json/recommended'],
		rules: {
			'json/no-duplicate-keys': 'error',
		},
	},
	// JavaScript files
	{
		files: ['**/*.js'],
		language: '@/js',
		plugins: { js },
		extends: ['js/recommended'],
		linterOptions:{
			// silence warnings about inert // eslint-disable-next-line xxx
			reportUnusedDisableDirectives: "off",
		},
		languageOptions: {
			sourceType: 'script',
			ecmaVersion: 2026, // 2015 == ECMA6
			globals: {
				...globals.browser,
				/* LuCI runtime / cbi exports */
				_: 'readonly',
				N_: 'readonly',
				L: 'readonly',
				E: 'readonly',
				TR: 'readonly',
				cbi_d: 'readonly',
				cbi_strings: 'readonly',
				cbi_d_add: 'readonly',
				cbi_d_check: 'readonly',
				cbi_d_checkvalue: 'readonly',
				cbi_d_update: 'readonly',
				cbi_init: 'readonly',
				cbi_update_table: 'readonly',
				cbi_validate_form: 'readonly',
				cbi_validate_field: 'readonly',
				cbi_validate_named_section_add: 'readonly',
				cbi_validate_reset: 'readonly',
				cbi_row_swap: 'readonly',
				cbi_tag_last: 'readonly',
				cbi_submit: 'readonly',
				cbi_dropdown_init: 'readonly',
				isElem: 'readonly',
				toElem: 'readonly',
				matchesElem: 'readonly',
				findParent: 'readonly',
				sfh: 'readonly',
				renderBadge: 'readonly', // found in theme templates
				/* modules */
				baseclass: 'readonly',
				dom: 'readonly',
				firewall: 'readonly',
				fwtool: 'readonly',
				form: 'readonly',
				fs: 'readonly',
				network: 'readonly',
				nettools: 'readonly',
				poll: 'readonly',
				random: 'readonly',
				request: 'readonly',
				session: 'readonly',
				rpc: 'readonly',
				uci: 'readonly',
				ui: 'readonly',
				uqr: 'readonly',
				validation: 'readonly',
				view: 'readonly',
				widgets: 'readonly',
				/* dockerman */
				dm2: 'readonly',
				jsapi: 'readonly',
			},
			parserOptions: {
				ecmaFeatures: {
					globalReturn: true,
				}
			},
		},
		rules: { // 0: off, 1: warn, 2: error
			'strict': 0,
			'no-prototype-builtins': 0,
			'no-empty': 0,
			'no-undef': 'warn',
			'no-unused-vars': ['off', { "caughtErrors": "none" }],
			'no-regex-spaces': 0,
			'no-control-regex': 0,
		}
	},
	{
		extends: ['jsdoc/recommended'],       // run jsdoc recommended rules
		files: ['modules/luci-base/**/*.js'], // ... but only on these js files
		plugins: { jsdoc },
		rules: {
			/* use these settings when linting the checked out repo */
			// ...jsdoc_less_relaxed_rules
			/* ... and use these settings for the repo (less noisy) */
			...jsdoc_relaxed_rules
		},
	}
]);