Giter Site home page Giter Site logo

forcedotcom / eslint-plugin-aura Goto Github PK

View Code? Open in Web Editor NEW
27.0 11.0 9.0 533 KB

Salesforce Lightning (Aura) specific linting rules for ESLint

License: BSD 3-Clause "New" or "Revised" License

JavaScript 99.77% Shell 0.23%
eslint-plugin eslint eslintplugin salesforce salesforce-lightning aura aura-framework

eslint-plugin-aura's Introduction

eslint-plugin-aura

Build status NPM version

Salesforce Lightning (Aura) specific linting rules for ESLint.

Installation

npm install --save-dev @salesforce/eslint-plugin-aura

Usage

Add this plugin to your ESLint configuration and extend your desired configuration. See ESLint documentation for details.

Example:

{
  "plugins": ["@salesforce/eslint-plugin-aura"],
  "extends": [
    "plugin:@salesforce/eslint-plugin-aura/recommended",
    "plugin:@salesforce/eslint-plugin-aura/locker"
  ]
}

Rules

Aura

Rule ID Description
aura/aura-api validate Aura APIs
aura/getevt-markup-prefix verify the presence of the markup:// prefix for events accessed via $A.getEvt()
aura/no-deprecated-aura-error prevent usage of $A.error
aura/no-deprecated-component-creation prevent usage of deprecated component creation methods
aura/no-deprecated-event-creation prevent usage of deprecated event creation methods

Locker

Rule ID Description
aura/ecma-intrinsics validate JavaScript intrinsic APIs
aura/secure-document validate secure document public APIs
aura/secure-window validate secure window public APIs

Configurations

This package exposes 2 configurations for your usage.

@salesforce/eslint-plugin-aura/recommended configuration

Goal: Prevent common pitfalls with Lightning component development, and enforce other Salesforce platform restrictions.

Rules:

@salesforce/eslint-plugin-aura/locker configuration

Goal: Prevent Lightning Locker violations.

Rules:

  • @salesforce/eslint-plugin-aura/recommended rules.
  • Proper usage of document and window via the secure-document and secure-window rules, respectively.
  • Proper usage of Javascript intrinsic APIs via the ecma-intrinsics rule.

eslint-plugin-aura's People

Contributors

dependabot[bot] avatar pmdartus avatar rochejul avatar svc-scm avatar touzoku avatar yodadacoda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eslint-plugin-aura's Issues

Upgrading eslint to 9 cause warnings in command line.

Upgraded eslint to 9.1.1 and got those warnings in command line:

npm warn Could not resolve dependency:
npm warn peer eslint@"^7 || ^8" from @salesforce/[email protected]
npm warn node_modules/@salesforce/eslint-plugin-aura
npm warn dev @salesforce/eslint-plugin-aura@"^2.1.0" from the root project
npm warn ERESOLVE overriding peer dependency
npm warn While resolving: [email protected]
npm warn Found: [email protected]
npm warn node_modules/eslint
npm warn dev eslint@"^9.1.1" from the root project
npm warn 16 more (@babel/eslint-parser, ...)
npm warn

Please upgrade plugin to be compatible with version 9.

library javascript files should not return an "not used function"

Aura architecture provides the ability to create kinds of service. We should create a function which is the same as the same of the javascript file.

However, as this is not used into the file and this is not exported through a mechanism, we have an eslint error / warning, due to an "unused function"

A nice feature should to disable this error for this kind of situation

Keyword 'const' is reserved

What did I do:
Add ESLint with the eslint-plugin-aura to a existing codebase in order to lint the aura component js files.

// .eslintrc.json
{
  "plugins": [
    "@salesforce/eslint-plugin-aura"
  ],
  "extends": [
    "plugin:@salesforce/eslint-plugin-aura/recommended"
  ],
  "rules": {
    "func-names": ["error", "never"],
    "quote-props": ["error", "as-needed"],
    "no-magic-numbers": "off",
    "max-nested-callbacks": "warn",
    "camelcase": "warn",
    "lines-around-comment": ["error", {"beforeLineComment":  false}],
    "no-multiple-empty-lines": ["error",
      {
        "max": 1
      }],
    "semi": ["error", "never"]
  }
}

What happens:
In all the files the following error occures error Parsing error: The keyword 'const' is reserved

Workaround:
add ecma version 6 to the config file

"parserOptions": {
    "ecmaVersion": 6
      },

Plugin not working with eslint 8.3.0

Hi,

I can't get the plugin to work with eslint 8.3.0. I get an issue in ESLint saying that it can't find the plugin @salesforce/eslint-plugin-aura

Could you fix ? Or maybe this plugin is deprecated ?

Best regards

Review recommended rules config for func-names and no-unused-expressions

Currently 'func-names': ['error', 'always'] and 'no-unused-expressions': 'error' produce errors for a perfectly valid aura controller code as below:

({
    myAction: function (component, event, helper) {
        return false
    }
})

This issue requires research on how these rules could be improved (in lieu of just disabling them).

Allow usage of ESLint v7

Current version of eslint-plugin-aura has an outdated dependency on [email protected] which doesn't support the latest major version of ESLint (v7 which is close to a year old).

This results in broken builds:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: [email protected]
npm ERR! node_modules/eslint
npm ERR!   dev eslint@"^7.20.0" from the root project
npm ERR!   peer eslint@"^6 || ^7" from @salesforce/[email protected]
npm ERR!   node_modules/@salesforce/eslint-config-lwc
npm ERR!     dev @salesforce/eslint-config-lwc@"^0.9.0" from the root project
npm ERR!   6 more (@salesforce/eslint-plugin-aura, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@"^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0" from [email protected]
npm ERR! node_modules/@salesforce/eslint-plugin-aura/node_modules/eslint-plugin-compat
npm ERR!   eslint-plugin-compat@"3.3.0" from @salesforce/[email protected]
npm ERR!   node_modules/@salesforce/eslint-plugin-aura
npm ERR!     dev @salesforce/eslint-plugin-aura@"^1.4.0" from the root project

Plans for other cmp file linting?

I am a big fan of this library and have already started looking to integrate it into our team's workflow for standardizing lightning component bundle javascript files (*Helper.js, *Renderer.js, *Controller.js)

I was curious if there is/will be any plans to implement something similar to a JSX parser for the .cmp files so that can be linted as well (see https://github.com/yannickcr/eslint-plugin-react for an example)? Right now I am utilizing the JSX parser for linting simple things like spacing and html attributes, but it would be fantastic to handle it properly with either an extension of JSX parsing or completely custom parsing for aura component .cmp files.

It would pair well with the https://github.com/forcedotcom/eslint-plugin-visualforce along with all the other linting efforts going on for the sfdx approach to development on salesforce

How can I configure this to ignore IE11?

I see this repository depends on eslint-plugin-compat which allows us to specify which browsers to target. I am seeing a lot of errors in my js components dealing with IE11 issues. When I attempt to tell eslint-plugin-compat to only target chrome, this plugin still fails on IE11 issues.

Proposal - Version 2.0.0 release tracking

Major changes

  • Add support for ESLint v7 (#13).
    • ESLint 7 was released more than a year ago, I think it is reasonable to bump the peerDependency to 7.
    • As of today the peer-dependency is defined as >= 5.0.0. I would advocate changing this to ^7. The CI is not setup today to ensure that all the ESLint versions between 5 and 7 are compatible with this plugin. I would require updating the peerDependency value once ESLint 8 is released, which is fine as we would need to make sure the plugin is still compatible.
  • Update minimal Node.js supported version to 12. #22

Minor changes

  • Remove all the styles related rules from the config. Today all new SFDX projects come with prettier already installed. Enforcing styling-related rules is unnecessary IMO.

Nice to have

  • Update remaining dev dependencies #17
  • Add proper testing for rules and configuration
    • Use mocha (or some other test runner) to run the tests #18
    • Improve existing rules coverage
    • Add smoke test for configuration
  • Run ESLint and Prettier as part of the CI #20
  • Add missing documentation for aura-service rule

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.