New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-ember

Package Overview
Dependencies
Maintainers
6
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-ember - npm Package Compare versions

Comparing version 6.8.2 to 6.9.0

lib/rules/require-computed-property-dependencies.js

16

CHANGELOG.md

@@ -0,1 +1,17 @@

## v6.9.0 (2019-08-12)
#### :rocket: Enhancement
* [#458](https://github.com/ember-cli/eslint-plugin-ember/pull/458) Add new rule `require-computed-property-dependencies` ([@bmish](https://github.com/bmish))
#### :bug: Bug Fix
* [#463](https://github.com/ember-cli/eslint-plugin-ember/pull/463) Fix false positives for import statements with `use-ember-data-rfc-395-imports` rule ([@fusion2004](https://github.com/fusion2004))
#### :house: Internal
* [#465](https://github.com/ember-cli/eslint-plugin-ember/pull/465) Add tests that rules are setup correctly (not missing tests, docs, exports, etc) ([@bmish](https://github.com/bmish))
* [#466](https://github.com/ember-cli/eslint-plugin-ember/pull/466) Fix eslint 6 rule test parser error ([@bmish](https://github.com/bmish))
#### Committers: 2
- Bryan Mishkin ([@bmish](https://github.com/bmish))
- Mark Oleson ([@fusion2004](https://github.com/fusion2004))
## v6.8.2 (2019-08-08)

@@ -2,0 +18,0 @@

4

lib/index.js

@@ -13,2 +13,3 @@ 'use strict';

'closure-actions': require('./rules/closure-actions'),
'computed-property-getters': require('./rules/computed-property-getters'),
'jquery-ember-run': require('./rules/jquery-ember-run'),

@@ -50,6 +51,7 @@ 'local-modules': require('./rules/local-modules'),

'order-in-routes': require('./rules/order-in-routes'),
'route-path-style': require('./rules/route-path-style'),
'require-computed-macros': require('./rules/require-computed-macros'),
'require-computed-property-dependencies': require('./rules/require-computed-property-dependencies'),
'require-return-from-computed': require('./rules/require-return-from-computed'),
'require-super-in-init': require('./rules/require-super-in-init'),
'route-path-style': require('./rules/route-path-style'),
'routes-segments-snake-case': require('./rules/routes-segments-snake-case'),

@@ -56,0 +58,0 @@ 'use-brace-expansion': require('./rules/use-brace-expansion'),

@@ -53,2 +53,3 @@ /*

"ember/require-computed-macros": "off",
"ember/require-computed-property-dependencies": "off",
"ember/require-return-from-computed": "off",

@@ -55,0 +56,0 @@ "ember/require-super-in-init": "error",

@@ -5,2 +5,3 @@ 'use strict';

const emberUtils = require('../utils/ember');
const propertyGetterUtils = require('../utils/property-getter');

@@ -26,30 +27,2 @@ //------------------------------------------------------------------------------

/**
* Checks if a MemberExpression node looks like `this.x` or `this.x.y`.
*
* @param {Node} node The MemberExpression node to check.
* @returns {boolean} Whether the node looks like `this.x` or `this.x.y`.
*/
function isSimpleThisExpression(node) {
if (!utils.isMemberExpression(node)) {
return false;
}
let current = node;
while (current !== null) {
if (utils.isMemberExpression(current)) {
if (!utils.isIdentifier(current.property)) {
return false;
}
current = current.object;
} else if (utils.isThisExpression(current)) {
return true;
} else {
return false;
}
}
return false;
}
/**
* Checks if a LogicalExpression looks like `this.x && this.y && this.z`

@@ -69,3 +42,3 @@ * containing only simple `this.x` MemberExpression nodes.

if (utils.isLogicalExpression(current)) {
if (!isSimpleThisExpression(current.right)) {
if (!propertyGetterUtils.isSimpleThisExpression(current.right)) {
return false;

@@ -77,3 +50,3 @@ }

current = current.left;
} else if (isSimpleThisExpression(current)) {
} else if (propertyGetterUtils.isSimpleThisExpression(current)) {
return true;

@@ -132,16 +105,2 @@ } else {

create(context) {
/**
* Converts a Node containing a ThisExpression to its dependent key.
*
* Example Input: A Node with this source code: `this.x.y`
* Example Output: 'x.y'
*
* @param {Node} node a MemberExpression node that looks like `this.x` or `this.x.y`.
* @returns {String} The dependent key of the input node (without `this.`).
*/
function nodeToDependentKey(nodeWithThisExpression) {
const sourceCode = context.getSourceCode();
return sourceCode.getText(nodeWithThisExpression).replace(/^this\./, '');
}
function reportSingleArg(nodeComputedProperty, nodeWithThisExpression, macro) {

@@ -152,3 +111,3 @@ context.report({

fix(fixer) {
const text = nodeToDependentKey(nodeWithThisExpression);
const text = propertyGetterUtils.nodeToDependentKey(nodeWithThisExpression, context);
return fixer.replaceText(nodeComputedProperty, `computed.${macro}('${text}')`);

@@ -165,3 +124,6 @@ },

const sourceCode = context.getSourceCode();
const textLeft = nodeToDependentKey(nodeBinaryExpression.left);
const textLeft = propertyGetterUtils.nodeToDependentKey(
nodeBinaryExpression.left,
context
);
const textRight = sourceCode.getText(nodeBinaryExpression.right);

@@ -182,3 +144,3 @@ return fixer.replaceText(

const text = getThisExpressions(nodeLogicalExpression)
.map(nodeToDependentKey)
.map(node => propertyGetterUtils.nodeToDependentKey(node, context))
.join("', '");

@@ -218,3 +180,3 @@ return fixer.replaceText(nodeComputedProperty, `computed.${macro}('${text}')`);

statement.operator === '!' &&
isSimpleThisExpression(statement.argument)
propertyGetterUtils.isSimpleThisExpression(statement.argument)
) {

@@ -231,3 +193,3 @@ reportSingleArg(node, statement.argument, 'not');

utils.isLiteral(statement.right) &&
isSimpleThisExpression(statement.left)
propertyGetterUtils.isSimpleThisExpression(statement.left)
) {

@@ -245,3 +207,3 @@ if (statement.operator === '===') {

}
} else if (isSimpleThisExpression(statement)) {
} else if (propertyGetterUtils.isSimpleThisExpression(statement)) {
reportSingleArg(node, statement, 'reads');

@@ -248,0 +210,0 @@ }

@@ -102,3 +102,3 @@ 'use strict';

if (node.source.value.startsWith('ember-data')) {
if (node.source.value === 'ember-data' || node.source.value.startsWith('ember-data/')) {
context.report(node, message);

@@ -105,0 +105,0 @@ }

@@ -14,2 +14,3 @@ 'use strict';

isFunctionExpression,
isExpressionStatement,
isArrowFunctionExpression,

@@ -167,2 +168,12 @@ isConciseArrowFunctionWithCallExpression,

/**
* Check whether or not a node is an isExpressionStatement.
*
* @param {Object} node The node to check.
* @returns {boolean} Whether or not the node is an isExpressionStatement.
*/
function isExpressionStatement(node) {
return node !== undefined && node.type === 'ExpressionStatement';
}
/**
* Check whether or not a node is an ArrowFunctionExpression.

@@ -169,0 +180,0 @@ *

{
"name": "eslint-plugin-ember",
"version": "6.8.2",
"version": "6.9.0",
"description": "Eslint plugin for Ember.js apps",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -123,2 +123,3 @@ # eslint-plugin-ember

| :white_check_mark: | [no-side-effects](./docs/rules/no-side-effects.md) | Warns about unexpected side effects in computed properties |
| :wrench: | [require-computed-property-dependencies](./docs/rules/require-computed-property-dependencies.md) | Requires dependencies to be declared statically in computed properties |
| | [require-return-from-computed](./docs/rules/require-return-from-computed.md) | Warns about missing return statements in computed properties |

@@ -125,0 +126,0 @@ | :white_check_mark: | [require-super-in-init](./docs/rules/require-super-in-init.md) | Enforces super calls in init hooks |

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc