Skip to content

Commit ec7b712

Browse files
committed
Added eslint.config.mjs for improved linting setup
1 parent 55a7853 commit ec7b712

36 files changed

+2516
-1495
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Ignore artifacts:
2+
build
3+
.idea/
4+
.vs/
5+
.vscode/
6+
bin/
7+
e2e/
8+
node_modules/
9+
nswag/
10+
obj/
11+
src/assets/
12+
dist/
13+
14+
*.css
15+
*.less
16+
*.min.*
17+
package.json
18+
package-lock.json
19+
yarn.lock
20+
*.json
21+
src/shared/service-proxies/service-proxies.ts

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/AbpCompanyName.AbpProjectName.Web.Mvc.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
1515
<PreserveCompilationReferences>true</PreserveCompilationReferences>
1616
</PropertyGroup>
17+
<ItemGroup>
18+
<Content Include="eslint.config.mjs" />
19+
</ItemGroup>
1720
<ItemGroup>
1821
<None Update="Dockerfile">
1922
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/bundles.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,11 @@
7272
},
7373
{
7474
"output": "view-resources/Views/_Bundles/datatables.ajax.min.js",
75-
"input": [
76-
"wwwroot/Common/datatables.ajax.js"
77-
]
75+
"input": ["wwwroot/Common/datatables.ajax.js"]
7876
},
7977
{
8078
"output": "view-resources/Views/_Bundles/helpers.min.js",
81-
"input": [
82-
"wwwroot/Common/helpers.js"
83-
]
79+
"input": ["wwwroot/Common/helpers.js"]
8480
}
8581
],
8682
"styles": [
@@ -115,9 +111,7 @@
115111
"scriptMappings": [
116112
{
117113
"outputFolder": "libs/moment-timezone",
118-
"input": [
119-
"node_modules/moment-timezone/*.js"
120-
]
114+
"input": ["node_modules/moment-timezone/*.js"]
121115
}
122116
]
123-
}
117+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { includeIgnoreFile } from "@eslint/compat";
2+
import { fileURLToPath } from "node:url";
3+
import path from "node:path";
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = path.dirname(__filename);
7+
const gitignorePath = path.resolve(__dirname, ".gitignore");
8+
9+
export default [
10+
{
11+
files: ["wwwroot/js/**/*.js"],
12+
ignores: ["wwwroot/js/**/*.min.js"],
13+
languageOptions: {
14+
ecmaVersion: 2021,
15+
sourceType: "script",
16+
globals: {
17+
$: "readonly",
18+
jQuery: "readonly",
19+
console: "readonly",
20+
window: "readonly",
21+
document: "readonly",
22+
},
23+
},
24+
plugins: {},
25+
rules: {
26+
"no-unused-vars": "off",
27+
"no-undef": "off",
28+
"no-console": "off",
29+
eqeqeq: "error",
30+
"no-undef": "error",
31+
},
32+
},
33+
includeIgnoreFile(gitignorePath),
34+
{
35+
ignores: ["wwwroot/js/**/*.min.js"],
36+
},
37+
];

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/gulpfile.mjs

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
1-
import gulp from 'gulp';
2-
import path from 'path';
3-
import fs from 'fs';
4-
import merge from 'merge-stream';
5-
import { globbySync } from 'globby'
6-
import concat from 'gulp-concat';
7-
import less from 'gulp-less';
8-
import gulpTerser from 'gulp-terser';
9-
import { minify } from 'terser'
10-
import cleanCss from 'gulp-clean-css';
11-
import postcss from 'gulp-postcss';
12-
import url from 'postcss-url';
1+
import gulp from "gulp";
2+
import path from "path";
3+
import fs from "fs";
4+
import merge from "merge-stream";
5+
import { globbySync } from "globby";
6+
import concat from "gulp-concat";
7+
import less from "gulp-less";
8+
import gulpTerser from "gulp-terser";
9+
import { minify } from "terser";
10+
import cleanCss from "gulp-clean-css";
11+
import postcss from "gulp-postcss";
12+
import url from "postcss-url";
1313

1414
const __dirname = import.meta.dirname;
1515

16-
const bundleConfig = JSON.parse(fs.readFileSync('./bundles.json', 'utf-8'));
16+
const bundleConfig = JSON.parse(fs.readFileSync("./bundles.json", "utf-8"));
1717

1818
var production = false;
1919

2020
var styleEntries = {};
2121
var scriptEntries = {};
2222

23-
var viewScripts = globbySync(['./wwwroot/view-resources/**/*.js', '!./wwwroot/view-resources/**/*.min.js']);
23+
var viewScripts = globbySync([
24+
"./wwwroot/view-resources/**/*.js",
25+
"!./wwwroot/view-resources/**/*.min.js",
26+
]);
2427

2528
var viewStyles = globbySync([
26-
'./wwwroot/view-resources/**/*.css',
27-
'./wwwroot/view-resources/**/*.less',
28-
'!./wwwroot/view-resources/**/*.min.css',
29+
"./wwwroot/view-resources/**/*.css",
30+
"./wwwroot/view-resources/**/*.less",
31+
"!./wwwroot/view-resources/**/*.min.css",
2932
]);
3033

3134
function processInputDefinition(input) {
3235
var result = [];
3336
for (var i = 0; i < input.length; i++) {
3437
var url = input[i];
35-
if (url.startsWith('!')) {
36-
result.push('!' + path.resolve(__dirname, url.substring(1)));
38+
if (url.startsWith("!")) {
39+
result.push("!" + path.resolve(__dirname, url.substring(1)));
3740
} else {
3841
result.push(path.resolve(__dirname, url));
3942
}
@@ -53,8 +56,10 @@ function fillScriptBundles() {
5356

5457
// View scripts
5558
for (var i = 0; i < viewScripts.length; i++) {
56-
var viewScriptName = viewScripts[i].replace('./wwwroot/', '');
57-
scriptEntries[viewScriptName.replace('.js', '.min.js')] = [path.resolve(__dirname, viewScripts[i])];
59+
var viewScriptName = viewScripts[i].replace("./wwwroot/", "");
60+
scriptEntries[viewScriptName.replace(".js", ".min.js")] = [
61+
path.resolve(__dirname, viewScripts[i]),
62+
];
5863
}
5964
}
6065

@@ -68,14 +73,18 @@ function fillStyleBundles() {
6873

6974
// View styles
7075
for (var j = 0; j < viewStyles.length; j++) {
71-
var viewStyleName = viewStyles[j].replace('./wwwroot/', '');
76+
var viewStyleName = viewStyles[j].replace("./wwwroot/", "");
7277

73-
if (viewStyleName.indexOf('.css') >= 0) {
74-
styleEntries[viewStyleName.replace('.css', '.min.css')] = [path.resolve(__dirname, 'wwwroot/' + viewStyleName)];
78+
if (viewStyleName.indexOf(".css") >= 0) {
79+
styleEntries[viewStyleName.replace(".css", ".min.css")] = [
80+
path.resolve(__dirname, "wwwroot/" + viewStyleName),
81+
];
7582
}
7683

77-
if (viewStyleName.indexOf('.less') >= 0) {
78-
styleEntries[viewStyleName.replace('.less', '.min.css')] = [path.resolve(__dirname, 'wwwroot/' + viewStyleName)];
84+
if (viewStyleName.indexOf(".less") >= 0) {
85+
styleEntries[viewStyleName.replace(".less", ".min.css")] = [
86+
path.resolve(__dirname, "wwwroot/" + viewStyleName),
87+
];
7988
}
8089
}
8190
}
@@ -93,7 +102,10 @@ function fillScriptMappings() {
93102
var scriptBundle = bundleConfig.scriptMappings[k];
94103
var inputFilesToBeCopied = globbySync(scriptBundle.input);
95104
for (var j = 0; j < inputFilesToBeCopied.length; j++) {
96-
var outputFileName = path.join(scriptBundle.outputFolder, getFileNameFromPath(inputFilesToBeCopied[j]));
105+
var outputFileName = path.join(
106+
scriptBundle.outputFolder,
107+
getFileNameFromPath(inputFilesToBeCopied[j]),
108+
);
97109
scriptEntries[outputFileName] = [inputFilesToBeCopied[j]];
98110
}
99111
}
@@ -117,7 +129,9 @@ function createScriptBundle(script) {
117129
stream = stream.pipe(gulpTerser({}, minify));
118130
}
119131

120-
return stream.pipe(concat(bundleName)).pipe(gulp.dest('wwwroot/' + bundlePath));
132+
return stream
133+
.pipe(concat(bundleName))
134+
.pipe(gulp.dest("wwwroot/" + bundlePath));
121135
}
122136

123137
function createStyleBundles() {
@@ -130,48 +144,50 @@ function createStyleBundles() {
130144
}
131145

132146
function createStyleBundle(style) {
133-
let basePath = process.argv.length >= 5 ? process.argv[4] : '';
147+
let basePath = process.argv.length >= 5 ? process.argv[4] : "";
134148

135149
var bundleName = getFileNameFromPath(style);
136150
var bundlePath = getPathWithoutFileNameFromPath(style);
137151

138152
var options = {
139153
url: function (asset) {
140154
// Ignore absolute URLs
141-
if (asset.url.substring(0, 1) === '/') {
155+
if (asset.url.substring(0, 1) === "/") {
142156
return asset.url;
143157
}
144158

145-
var outputFolder = '';
159+
var outputFolder = "";
146160

147161
if (asset.url.match(/\.(png|svg|jpg|gif)$/)) {
148-
outputFolder = basePath + 'dist/img';
162+
outputFolder = basePath + "dist/img";
149163
} else if (asset.url.match(/\.(woff|woff2|eot|ttf|otf)[?]{0,1}.*$/)) {
150-
outputFolder = basePath + 'dist/fonts';
164+
outputFolder = basePath + "dist/fonts";
151165
} else {
152166
// Ignore not recognized assets like data:image etc...
153167
return asset.url;
154168
}
155169

156170
var fileName = path.basename(asset.absolutePath);
157-
var outputPath = path.join(__dirname, '/wwwroot/' + outputFolder + '/');
171+
var outputPath = path.join(__dirname, "/wwwroot/" + outputFolder + "/");
158172

159173
gulp.src(asset.absolutePath).pipe(gulp.dest(outputPath));
160174

161-
return '/' + outputFolder + '/' + fileName;
175+
return "/" + outputFolder + "/" + fileName;
162176
},
163177
};
164178

165179
var stream = gulp
166180
.src(styleEntries[style])
167181
.pipe(postcss([url(options)]))
168-
.pipe(less({ math: 'parens-division' }));
182+
.pipe(less({ math: "parens-division" }));
169183

170184
if (production) {
171185
stream = stream.pipe(cleanCss());
172186
}
173187

174-
return stream.pipe(concat(bundleName)).pipe(gulp.dest('wwwroot/' + bundlePath));
188+
return stream
189+
.pipe(concat(bundleName))
190+
.pipe(gulp.dest("wwwroot/" + bundlePath));
175191
}
176192

177193
function findMatchingElements(path, array) {
@@ -189,7 +205,7 @@ function watchScriptEntries() {
189205
for (var script in scriptEntries) {
190206
var watcher = gulp.watch(scriptEntries[script]);
191207

192-
watcher.on('change', function (path, stats) {
208+
watcher.on("change", function (path, stats) {
193209
console.log(`${path} updated`);
194210

195211
var changedBundles = findMatchingElements(path, scriptEntries);
@@ -205,7 +221,7 @@ function watchStyleEntries() {
205221
for (var style in styleEntries) {
206222
var watcher = gulp.watch(styleEntries[style]);
207223

208-
watcher.on('change', function (path, stats) {
224+
watcher.on("change", function (path, stats) {
209225
console.log(`${path} updated`);
210226

211227
var changedBundles = findMatchingElements(path, styleEntries);
@@ -241,7 +257,7 @@ function buildDev() {
241257
watchScriptEntries();
242258
watchStyleEntries();
243259

244-
console.log('Bundles are being created, please wait...');
260+
console.log("Bundles are being created, please wait...");
245261

246262
return merge(scriptTasks.concat(styleTasks));
247263
}
@@ -252,9 +268,9 @@ function checkBundleItem(bundleItem) {
252268
for (var i = 0; i < definition.length; i++) {
253269
var url = definition[i];
254270
if (
255-
typeof url == 'undefined' ||
256-
url.startsWith('!') ||
257-
url.indexOf('*') >= 0 ||
271+
typeof url == "undefined" ||
272+
url.startsWith("!") ||
273+
url.indexOf("*") >= 0 ||
258274
url.match(/^[0-9]+$/) != null //only digit
259275
) {
260276
continue;
@@ -269,14 +285,11 @@ function checkFile(path) {
269285
if (fs.existsSync(path)) {
270286
//file exists
271287
} else {
272-
console.error('File not found: ' + path);
288+
console.error("File not found: " + path);
273289
}
274290
} catch (err) {
275-
console.error('File not found: ' + path);
291+
console.error("File not found: " + path);
276292
}
277293
}
278294

279-
export {
280-
build as build,
281-
buildDev as buildDev
282-
}
295+
export { build as build, buildDev as buildDev };

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Mvc/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"name": "abptemplate",
33
"scripts": {
44
"create-bundles": "yarn && gulp buildDev",
5-
"build": "yarn && gulp build"
5+
"build": "yarn && gulp build",
6+
"prettier": "npx prettier --write .",
7+
"lint": "eslint"
68
},
79
"version": "10.1.0",
810
"license": "MIT",
@@ -32,7 +34,11 @@
3234
"toastr": "2.1.4"
3335
},
3436
"devDependencies": {
37+
"@eslint/compat": "^1.2.9",
3538
"@types/node": "^22.13.5",
39+
"eslint": "^9.26.0",
40+
"eslint-plugin-jquery": "^1.5.1",
41+
"globals": "^16.1.0",
3642
"globby": "^14.1.0",
3743
"gulp": "^4.0.2",
3844
"gulp-clean-css": "^4.3.0",

0 commit comments

Comments
 (0)