Loading...

Power Apps ESLint plugin replaces Solution Checker for TypeScript code

Power Apps ESLint plugin replaces Solution Checker for TypeScript code

The Power Apps team have had a long-standing quality tool called the Solution Checker. This was built into the Dataverse solution management interface, ALM Power Platform Build Tools and even a PowerShell version. The challenge with the Solution Checker has always been that by the time you find out about the issues, it's often too late and the solution has been committed to source control and is already in the CI/CD pipeline, and furthermore the results were often false positives due to the way that TypeScript 'transpiles' into JavaScript.

Now the Power Apps team have released an ESLint plugin that gives you warnings and errors as you write your code (if you have the eslint extension installed), or when you run ESLint at the command line.

I've previously written on using ESLint in your development environment - and this is a really welcome addition to the rule set. 

At this time, the rule-set is most applicable for Web Resource development at the moment with the majority describing deprecations, however, it is certainly worth adding them to PCF projects as well (alongside the other react recommended rules).

To install you use:

npm install @microsoft/eslint-plugin-power-apps --save-dev

To add to your existing .eslint.json file, add @microsoft/power-apps to the plugins section:

"plugins": [
    ...
    "@microsoft/power-apps"
],

Then add each of the rules to the rules section with the level you want to enforce: 

"rules": {
  "@microsoft/power-apps/avoid-2011-api": "error",
  "@microsoft/power-apps/avoid-browser-specific-api": "error",
  "@microsoft/power-apps/avoid-crm2011-service-odata": "warn",
  "@microsoft/power-apps/avoid-crm2011-service-soap": "warn",
  "@microsoft/power-apps/avoid-dom-form-event": "warn",
  "@microsoft/power-apps/avoid-dom-form": "warn",
  "@microsoft/power-apps/avoid-isactivitytype": "warn",
  "@microsoft/power-apps/avoid-modals": "warn",
  "@microsoft/power-apps/avoid-unpub-api": "warn",
  "@microsoft/power-apps/avoid-window-top": "warn",
  "@microsoft/power-apps/do-not-make-parent-assumption": "warn",
  "@microsoft/power-apps/use-async": "error",
  "@microsoft/power-apps/use-cached-webresource": "warn",
  "@microsoft/power-apps/use-client-context": "warn",
  "@microsoft/power-apps/use-global-context": "error",
  "@microsoft/power-apps/use-grid-api": "warn",
  "@microsoft/power-apps/use-navigation-api": "warn",
  "@microsoft/power-apps/use-offline": "warn",
  "@microsoft/power-apps/use-org-setting": "error",
  "@microsoft/power-apps/use-relative-uri": "warn",
  "@microsoft/power-apps/use-utility-dialogs": "warn"
}

I would really like to see a recommended set of rules that can be used like other ESLint rule sets, so when more rules are added we don't need to explicitly add them to the config. If you agree - please consider upvoting my suggestions!

My .esconfig looks something like the following for a Web Resource project:

{
  "parser": "@typescript-eslint/parser",
  "env": {
    "browser": true,
    "commonjs": true,
    "es6": true,
    "jest": true,
    "jasmine": true
  },
  "extends": [
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended",
    "prettier",
    "plugin:sonarjs/recommended"
  ],
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "plugins": [
    "@typescript-eslint",
    "prettier",
    "@microsoft/power-apps",
    "sonarjs"
  ],
  "ignorePatterns": [
    "**/generated/*.ts"
  ],
  "rules": {
    "prettier/prettier": "error",
    "eqeqeq": [
      2,
      "smart"
    ],
    "prettier/prettier": "error",
    "arrow-body-style": "off",
    "prefer-arrow-callback": "off",
    "linebreak-style": [
      "error",
      "windows"
    ],
    "quotes": [
      "error",
      "double"
    ],
    "semi": [
      "error",
      "always"
    ],
    "@microsoft/power-apps/avoid-2011-api": "error",
    "@microsoft/power-apps/avoid-browser-specific-api": "error",
    "@microsoft/power-apps/avoid-crm2011-service-odata": "warn",
    "@microsoft/power-apps/avoid-crm2011-service-soap": "warn",
    "@microsoft/power-apps/avoid-dom-form-event": "warn",
    "@microsoft/power-apps/avoid-dom-form": "warn",
    "@microsoft/power-apps/avoid-isactivitytype": "warn",
    "@microsoft/power-apps/avoid-modals": "warn",
    "@microsoft/power-apps/avoid-unpub-api": "warn",
    "@microsoft/power-apps/avoid-window-top": "warn",
    "@microsoft/power-apps/do-not-make-parent-assumption": "warn",
    "@microsoft/power-apps/use-async": "error",
    "@microsoft/power-apps/use-cached-webresource": "warn",
    "@microsoft/power-apps/use-client-context": "warn",
    "@microsoft/power-apps/use-global-context": "error",
    "@microsoft/power-apps/use-grid-api": "warn",
    "@microsoft/power-apps/use-navigation-api": "warn",
    "@microsoft/power-apps/use-offline": "warn",
    "@microsoft/power-apps/use-org-setting": "error",
    "@microsoft/power-apps/use-relative-uri": "warn",
    "@microsoft/power-apps/use-utility-dialogs": "warn"
  }
}

 

Note: This uses the prettier and sonarjs plugins that you will also need to install.

I also add the following scripts to my package.json:

"lint": "eslint **/*.ts",
"lint:fix": "npm run lint -- --fix",

These then allow you to run the rules across the entire project and automatically fix them where possible using npm run lint:fix.

I really love how the solution package has evolved into this set of pro-coder-friendly ESLint rules. I can't wait to see how it develops with more rules over time.

Read more on the official blog post from Microsoft.

Take a look at the npm package information for eslint-plugin-power-apps.

Published on:

Learn more
Develop 1 - Dynamics 365 Architecture Services
Develop 1 - Dynamics 365 Architecture Services

Share post:

Related posts

Boosting Canvas Apps with Copilot Control in Power Apps: A Complete Step-by-Step Guide

The Copilot control is a powerful AI assistant that allows users to engage with data in Canvas Apps using natural language conversations. By i...

6 hours ago

Power Apps – Update your firewall rules to add the new telemetry endpoints by February 20, 2025

We are in the process of updating client telemetry endpoints. These endpoints allow Microsoft to gather telemetry to support customers in reso...

8 hours ago

Power Apps – Work with existing tables when visualizing complex data

We are announcing the work with existing tables when visualizing complex data feature for Power Apps. This feature allows for leveraging your ...

8 hours ago

SQL Server environment variables available for Power Apps

We are excited to announce that SQL Server environment variables (Entra) for Power Apps support is currently rolling out and will be in Previe...

16 hours ago

Component Libraries for Modern Themes – Power Apps

Ready to take your Power Apps theming game to the next level? In this video, I’ll show you how to transform the Power Apps Modern... The post ...

4 days ago

Using Power Automate Desktop to do automated testing Power Apps

Power Apps studio includes test tools, however these are not available when you use co-authoring. So how about automated testing your Canvas A...

7 days ago

Simplify Form-Filling with Smart Paste in Power Apps

In this blog post, we’ll explore a new feature called ‘Smart Paste’ that enhances the form-filling experience in Power Apps. Befor...

9 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy