From 958ea885f5f83245c4f619847f774b20240777d8 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Thu, 13 Jun 2024 11:54:24 -0700 Subject: [PATCH 1/2] improve duplicate checker --- .github/workflows/jscpd.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/jscpd.yml b/.github/workflows/jscpd.yml index b581bcd500e..da8af8687eb 100644 --- a/.github/workflows/jscpd.yml +++ b/.github/workflows/jscpd.yml @@ -1,6 +1,6 @@ name: Check for Duplicated Code -on: +on: pull_request_target: branches: - master @@ -100,11 +100,14 @@ jobs: const fs = require('fs'); const filteredReport = JSON.parse(fs.readFileSync('filtered-jscpd-report.json', 'utf8')); let comment = "Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:\n\n"; + function link(dup) { + return `https://github.com/${{ github.event.repository.full_name }}/blob/${{ github.event.pull_request.head.sha }}/${dup.name}#L${dup.start}-L${dup.end}` + } filteredReport.forEach(duplication => { - const firstFile = duplication.firstFile.name; - const secondFile = duplication.secondFile.name; + const firstFile = duplication.firstFile; + const secondFile = duplication.secondFile; const lines = duplication.lines; - comment += `- \`${firstFile}\` has ${lines} duplicated lines with \`${secondFile}\`\n`; + comment += `- [\`${firstFile.name}\`](${link(firstFile)}) has ${lines} duplicated lines with [\`${secondFile.name}\`](${link(secondFile)})\n`; }); comment += "\nReducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. Keep up the great work! 🚀"; github.rest.issues.createComment({ From 876b1d43cc20bb0bfecdd86a9745790ac6701cc2 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Thu, 13 Jun 2024 12:05:11 -0700 Subject: [PATCH 2/2] Update gulpfile.js --- gulpfile.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index 86c1b7fe509..0f0030afea1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -98,6 +98,30 @@ function lint(done) { .pipe(gulpif(isFixed, gulp.dest('./'))); }; +function lint2(done) { + if (argv.nolint) { + return done(); + } + const isFixed = function (file) { + return file.eslint != null && file.eslint.fixed; + } + return gulp.src([ + 'src/**/*.js', + 'modules/**/*.js', + 'libraries/**/*.js', + 'creative/**/*.js', + 'test/**/*.js', + 'plugins/**/*.js', + '!plugins/**/node_modules/**', + './*.js' + ], { base: './' }) + .pipe(eslint({ fix: !argv.nolintfix, quiet: !(typeof argv.lintWarnings === 'boolean' ? argv.lintWarnings : true) })) + .pipe(eslint.format('stylish')) + .pipe(eslint.failAfterError()) + .pipe(gulpif(isFixed, gulp.dest('./'))); +}; + + // View the code coverage report in the browser. function viewCoverage(done) { var coveragePort = 1999;