write our own little gulp-eslint which takes the eslint from our workspace root (#230115)

This commit is contained in:
Sandeep Somavarapu 2024-09-30 15:36:25 +02:00 committed by GitHub
parent ef44e67783
commit 841d51da29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 180 additions and 1072 deletions

View file

@ -8,17 +8,11 @@ const vfs = require('vinyl-fs');
const { eslintFilter } = require('./filters');
function eslint() {
const gulpeslint = require('gulp-eslint');
const eslint = require('./gulp-eslint');
return vfs
.src(eslintFilter, { base: '.', follow: true, allowEmpty: true })
.pipe(
gulpeslint({
configFile: '.eslintrc.json'
})
)
.pipe(gulpeslint.formatEach('compact'))
.pipe(
gulpeslint.results((results) => {
eslint((results) => {
if (results.warningCount > 0 || results.errorCount > 0) {
throw new Error('eslint failed with warnings and/or errors');
}

78
build/gulp-eslint.js Normal file
View file

@ -0,0 +1,78 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
const { ESLint } = require('eslint');
const { Transform } = require('stream');
const { relative } = require('path');
const fancyLog = require('fancy-log');
/**
* @param {Function} action - A function to handle all ESLint results
* @returns {stream} gulp file stream
*/
function eslint(action) {
const linter = new ESLint();
const formatter = linter.loadFormatter('compact');
const results = [];
results.errorCount = 0;
results.warningCount = 0;
return transform(
async (file, enc, cb) => {
const filePath = relative(process.cwd(), file.path);
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new Error('vinyl files with Stream contents are not supported'));
return;
}
try {
// TODO: Should this be checked?
if (await linter.isPathIgnored(filePath)) {
cb(null, file);
return;
}
const result = (await linter.lintText(file.contents.toString(), { filePath }))[0];
results.push(result);
results.errorCount += result.errorCount;
results.warningCount += result.warningCount;
const message = (await formatter).format([result]);
if (message) {
fancyLog(message);
}
cb(null, file);
} catch (error) {
cb(error);
}
},
(done) => {
try {
action(results);
done();
} catch (error) {
done(error);
}
});
}
function transform(transform, flush) {
return new Transform({
objectMode: true,
transform,
flush
});
}
module.exports = eslint;

View file

@ -21,7 +21,7 @@ const copyrightHeaderLines = [
];
function hygiene(some, linting = true) {
const gulpeslint = require('gulp-eslint');
const eslint = require('./gulp-eslint');
const gulpstylelint = require('./stylelint');
const formatter = require('./lib/formatter');
@ -172,13 +172,7 @@ function hygiene(some, linting = true) {
result
.pipe(filter(eslintFilter))
.pipe(
gulpeslint({
configFile: '.eslintrc.json'
})
)
.pipe(gulpeslint.formatEach('compact'))
.pipe(
gulpeslint.results((results) => {
eslint((results) => {
errorCount += results.warningCount;
errorCount += results.errorCount;
})

View file

@ -12,20 +12,20 @@ export class ActiveLineMarker {
this._update(previous && (previous.codeElement || previous.element));
}
_update(before: HTMLElement | undefined) {
private _update(before: HTMLElement | undefined) {
this._unmarkActiveElement(this._current);
this._markActiveElement(before);
this._current = before;
}
_unmarkActiveElement(element: HTMLElement | undefined) {
private _unmarkActiveElement(element: HTMLElement | undefined) {
if (!element) {
return;
}
element.classList.toggle('code-active-line', false);
}
_markActiveElement(element: HTMLElement | undefined) {
private _markActiveElement(element: HTMLElement | undefined) {
if (!element) {
return;
}

View file

@ -11,45 +11,45 @@ import { getStrings } from './strings';
* Shows an alert when there is a content security policy violation.
*/
export class CspAlerter {
private didShow = false;
private didHaveCspWarning = false;
private _didShow = false;
private _didHaveCspWarning = false;
private messaging?: MessagePoster;
private _messaging?: MessagePoster;
constructor(
private readonly settingsManager: SettingsManager,
private readonly _settingsManager: SettingsManager,
) {
document.addEventListener('securitypolicyviolation', () => {
this.onCspWarning();
this._onCspWarning();
});
window.addEventListener('message', (event) => {
if (event && event.data && event.data.name === 'vscode-did-block-svg') {
this.onCspWarning();
this._onCspWarning();
}
});
}
public setPoster(poster: MessagePoster) {
this.messaging = poster;
if (this.didHaveCspWarning) {
this.showCspWarning();
this._messaging = poster;
if (this._didHaveCspWarning) {
this._showCspWarning();
}
}
private onCspWarning() {
this.didHaveCspWarning = true;
this.showCspWarning();
private _onCspWarning() {
this._didHaveCspWarning = true;
this._showCspWarning();
}
private showCspWarning() {
private _showCspWarning() {
const strings = getStrings();
const settings = this.settingsManager.settings;
const settings = this._settingsManager.settings;
if (this.didShow || settings.disableSecurityWarnings || !this.messaging) {
if (this._didShow || settings.disableSecurityWarnings || !this._messaging) {
return;
}
this.didShow = true;
this._didShow = true;
const notification = document.createElement('a');
notification.innerText = strings.cspAlertMessageText;
@ -59,7 +59,7 @@ export class CspAlerter {
notification.setAttribute('role', 'button');
notification.setAttribute('aria-label', strings.cspAlertMessageLabel);
notification.onclick = () => {
this.messaging!.postMessage('showPreviewSecuritySelector', { source: settings.source });
this._messaging!.postMessage('showPreviewSecuritySelector', { source: settings.source });
};
document.body.appendChild(notification);
}

View file

@ -5,15 +5,15 @@
import { MessagePoster } from './messaging';
export class StyleLoadingMonitor {
private unloadedStyles: string[] = [];
private finishedLoading: boolean = false;
private _unloadedStyles: string[] = [];
private _finishedLoading: boolean = false;
private poster?: MessagePoster;
private _poster?: MessagePoster;
constructor() {
const onStyleLoadError = (event: any) => {
const source = event.target.dataset.source;
this.unloadedStyles.push(source);
this._unloadedStyles.push(source);
};
window.addEventListener('DOMContentLoaded', () => {
@ -25,18 +25,18 @@ export class StyleLoadingMonitor {
});
window.addEventListener('load', () => {
if (!this.unloadedStyles.length) {
if (!this._unloadedStyles.length) {
return;
}
this.finishedLoading = true;
this.poster?.postMessage('previewStyleLoadError', { unloadedStyles: this.unloadedStyles });
this._finishedLoading = true;
this._poster?.postMessage('previewStyleLoadError', { unloadedStyles: this._unloadedStyles });
});
}
public setPoster(poster: MessagePoster): void {
this.poster = poster;
if (this.finishedLoading) {
poster.postMessage('previewStyleLoadError', { unloadedStyles: this.unloadedStyles });
this._poster = poster;
if (this._finishedLoading) {
poster.postMessage('previewStyleLoadError', { unloadedStyles: this._unloadedStyles });
}
}
}

1092
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -114,6 +114,7 @@
"@swc/core": "1.3.62",
"@types/cookie": "^0.3.3",
"@types/debug": "^4.1.5",
"@types/eslint": "^8.56.10",
"@types/gulp-svgmin": "^1.2.1",
"@types/http-proxy-agent": "^2.0.1",
"@types/kerberos": "^1.1.2",
@ -165,7 +166,6 @@
"gulp-bom": "^3.0.0",
"gulp-buffer": "0.0.2",
"gulp-concat": "^2.6.1",
"gulp-eslint": "^5.0.0",
"gulp-filter": "^5.1.0",
"gulp-flatmap": "^1.0.2",
"gulp-gunzip": "^1.0.0",