diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 73a5f1645..03c797bf0 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -23,6 +23,12 @@ This is the **Microsoft Application Insights JavaScript SDK** - a browser-based ## Code Style & Patterns +### Required Before Each Commit +- Do not commit any changes that are only end-of-file whitespace changes +- Ensure all TypeScript files are formatted and imports are reordered correctly by running `npm run lint-fix` before committing + - This will apply ESLint fixes to all TypeScript files + - It will also reorder imports to maintain consistent style + ### TypeScript/JavaScript Conventions - Use **ES5-compatible** syntax for browser support and target ES5 for modern browsers - Prefer `function` declarations over arrow functions for better IE compatibility diff --git a/extensions/applicationinsights-clickanalytics-js/src/applicationinsights-clickanalytics-js.ts b/extensions/applicationinsights-clickanalytics-js/src/applicationinsights-clickanalytics-js.ts index 8041c5e93..5cf23e09c 100644 --- a/extensions/applicationinsights-clickanalytics-js/src/applicationinsights-clickanalytics-js.ts +++ b/extensions/applicationinsights-clickanalytics-js/src/applicationinsights-clickanalytics-js.ts @@ -1,9 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import { BehaviorEnumValidator, BehaviorMapValidator, BehaviorValueValidator, ClickAnalyticsPlugin } from "./ClickAnalyticsPlugin"; -import { IClickAnalyticsConfiguration, IValueCallback, ICustomDataTags, ICoreData, IPageTags, IPageActionTelemetry, IContent, IOverrideValues, IPageActionOverrideValues } from "./Interfaces/Datamodel"; import { Behavior } from "./Behaviours"; +import { BehaviorEnumValidator, BehaviorMapValidator, BehaviorValueValidator, ClickAnalyticsPlugin } from "./ClickAnalyticsPlugin"; +import { + IClickAnalyticsConfiguration, IContent, ICoreData, ICustomDataTags, IOverrideValues, IPageActionOverrideValues, IPageActionTelemetry, + IPageTags, IValueCallback +} from "./Interfaces/Datamodel"; // Re-export ICustomProperties from core export { ICustomProperties } from "@microsoft/applicationinsights-core-js"; diff --git a/gruntfile.js b/gruntfile.js index d827ba47e..394d7d22b 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -811,6 +811,23 @@ module.exports = function (grunt) { } } })); + + // Additional setup for lint-fix task + function getLintFixTasks() { + let packages = [ + "core", "common", "appinsights", "aisku", "aiskulite", "perfmarkmeasure", "properties", + "cfgsync", "deps", "debugplugin", "aichannel", "offlinechannel", "teechannel", + "1dsCore", "1dsPost", "rollupuglify", "rollupes5", "shims", "chrome-debug-extension", + "applicationinsights-web-snippet", "clickanalytics", "osplugin" + ]; + + let tasks = []; + packages.forEach(function(pkg) { + tasks.push("eslint-ts:" + pkg + "-lint-fix"); + }); + + return tasks; + } grunt.event.on('qunit.testStart', function (name) { grunt.log.ok('Running test: ' + name); @@ -823,8 +840,8 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadTasks('./tools/grunt-tasks'); - grunt.registerTask("default", ["ts:rollupuglify", "ts:rollupes5", "ts:rollupes5test", "qunit:rollupes5", "ts:shims", "ts:shimstest", "qunit:shims", "ts:default", "uglify:ai", "uglify:snippet"]); + grunt.registerTask("default", ["ts:rollupuglify", "ts:rollupes5", "ts:rollupes5test", "qunit:rollupes5", "ts:shims", "ts:shimstest", "qunit:shims", "ts:default", "uglify:ai", "uglify:snippet"]); grunt.registerTask("core", tsBuildActions("core", true)); grunt.registerTask("core-min", minTasks("core")); @@ -964,6 +981,9 @@ module.exports = function (grunt) { grunt.registerTask("example-aisku", tsBuildActions("example-aisku")); grunt.registerTask("example-dependency", tsBuildActions("example-dependency")); grunt.registerTask("example-cfgsync", tsBuildActions("example-cfgsync")); + + // Register the lint-fix task to run ESLint fix on all packages + grunt.registerTask("lint-fix", getLintFixTasks()); } catch (e) { console.error(e); console.error("stack: '" + e.stack + "', message: '" + e.message + "', name: '" + e.name + "'"); diff --git a/package.json b/package.json index 7747eb975..7ac081d12 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "test": "node common/scripts/install-run-rush.js test --verbose", "mintest": "node common/scripts/install-run-rush.js mintest --verbose", "lint": "node common/scripts/install-run-rush.js lint --verbose", + "lint-fix": "npm run ai-restore && grunt lint-fix", "perftest": "node common/scripts/install-run-rush.js perftest --verbose", "rollupes5": "grunt rollupes5", "rupdate": "node common/scripts/install-run-rush.js update --recheck --purge --full", diff --git a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts index 8f421015c..bca694a56 100644 --- a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts +++ b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts @@ -157,7 +157,7 @@ export interface IConfiguration { * [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload * event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK. * Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". - * + * * This can be used to avoid jQuery 3.7.1+ deprecation warnings and Chrome warnings about the unload event: * @example * ```javascript @@ -165,7 +165,7 @@ export interface IConfiguration { * disablePageUnloadEvents: ["unload"] * } * ``` - * + * * For more details, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/PageUnloadEvents.html). */ disablePageUnloadEvents?: string[]; @@ -174,14 +174,14 @@ export interface IConfiguration { * [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event * hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK. * Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). - * + * * @example * ```javascript * { * disablePageShowEvents: ["pageshow"] * } * ``` - * + * * For more details, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/PageUnloadEvents.html). */ disablePageShowEvents?: string[];