Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2.1

supported-eslint-versions: &supported-eslint-versions ["local", "7"]
supported-eslint-versions: &supported-eslint-versions ["local"]

jobs:
build:
Expand All @@ -12,7 +12,7 @@ jobs:
frozen in the package-lock.json is used.
default: "local"
docker:
- image: circleci/node
- image: cimg/node:20.12.2
steps:
- checkout

Expand Down
23 changes: 0 additions & 23 deletions .eslintrc.js

This file was deleted.

25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ $ npm install eslint @salesforce/eslint-plugin-lightning --save-dev

## Usage

Add this plugin to your ESLint configuration and extend your desired configuration. See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#configuring-plugins) for details.

```json
{
"plugin": ["@salesforce/eslint-plugin-lightning"],
"rules": {
"@salesforce/lightning/no-moment": "error",
"@salesforce/lightning/prefer-i18n-service": "error"
Import this plugin to your ESLint configuration file and apply your desired configuration. See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#configuring-plugins) for details.

```js
// eslint.config.js
const pluginLightning = require('@salesforce/eslint-plugin-lightning');

module.exports = [
{
'plugins': {
'@salesforce/lightning': pluginLightning,
}
'rules': {
'@salesforce/lightning/no-moment': 'error',
'@salesforce/lightning/prefer-i18n-service': 'error'
}
}
}
]
```

## Rules
Expand Down
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const globals = require('globals');
const js = require('@eslint/js');

module.exports = [
js.configs.recommended,
{
languageOptions: {
globals: {
...globals.mocha,
...globals.node,
},

sourceType: 'commonjs',
},

rules: {
strict: ['error', 'global'],
},
},
];
7 changes: 7 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
'use strict';

const { version } = require('../package.json');

const rules = {
'no-aura-localization-service': require('./rules/no-aura-localization-service'),
'no-moment': require('./rules/no-moment'),
Expand All @@ -14,5 +16,10 @@ const rules = {
};

module.exports = {
// https://eslint.org/docs/latest/extend/plugins#meta-data-in-plugins
meta: {
name: '@salesforce/eslint-plugin-lightning',
version,
},
rules,
};
3 changes: 2 additions & 1 deletion lib/rules/valid-apex-method-invocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
'use strict';

const { getScope } = require('../utils/context');
const { docUrl } = require('../utils/doc-url');

module.exports = {
Expand Down Expand Up @@ -98,7 +99,7 @@ module.exports = {
}

// Retrieve the callee reference from the current scope.
const scope = context.getScope();
const scope = getScope(context, node);
const methodReference = scope.references.find((r) => r.identifier === callee);

// Ignore the call expression if it can't be resolved from the current scope or if the
Expand Down
44 changes: 44 additions & 0 deletions lib/utils/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
'use strict';

/**
* Get the source code AST for the rule context.
* @param {RuleContext} context The context for the ESLint rule
* @returns {SourceCode} Object representing the source code AST
*/
function getSourceCode(context) {
return context.sourceCode ?? context.getSourceCode();
}

/**
* Get the ancestor nodes of a given node.
* @param {RuleContext} context The context for the ESLint rule
* @param {ASTNode} node An AST node
* @returns {ASTNode[]} Anscestor nodes
*/
function getAncestors(context, node) {
const sourceCode = getSourceCode(context);
return sourceCode.getAncestors ? sourceCode.getAncestors(node) : context.getAncestors();
}

/**
* Get the scope for a given node.
* @param {RuleContext} context The context for the ESLint rule
* @param {ASTNode} node An AST node
* @returns {Scope} The scope for a given node
*/
function getScope(context, node) {
const sourceCode = getSourceCode(context);
return sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
}

module.exports = {
getAncestors,
getScope,
getSourceCode,
};
Loading