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 7.4.0 to 7.4.1

11

CHANGELOG.md

@@ -0,1 +1,12 @@

## v7.4.1 (2019-11-07)
#### :bug: Bug Fix
* [#575](https://github.com/ember-cli/eslint-plugin-ember/pull/575) Update `avoid-leaking-state-in-ember-objects` rule to handle logical expressions ([@alexlafroscia](https://github.com/alexlafroscia))
* [#571](https://github.com/ember-cli/eslint-plugin-ember/pull/571) Update `avoid-leaking-state-in-ember-objects` rule to handle ternary expressions ([@alexlafroscia](https://github.com/alexlafroscia))
* [#573](https://github.com/ember-cli/eslint-plugin-ember/pull/573) Update `require-computed-macros` rule to handle `this.get('property')` (in addition to `this.property`) ([@bmish](https://github.com/bmish))
#### Committers: 2
- Alex LaFroscia ([@alexlafroscia](https://github.com/alexlafroscia))
- Bryan Mishkin ([@bmish](https://github.com/bmish))
## v7.4.0 (2019-11-06)

@@ -2,0 +13,0 @@

23

lib/rules/avoid-leaking-state-in-ember-objects.js

@@ -18,5 +18,16 @@ 'use strict';

const isAllowed = function(property) {
const value = property.value;
function isAllowedTernary(value) {
return (
types.isConditionalExpression(value) &&
isAllowed(value.consequent) &&
isAllowed(value.alternate)
);
}
function isAllowedLogicalExpression(value) {
return types.isLogicalExpression(value) && isAllowed(value.left) && isAllowed(value.right);
}
function isAllowed(value) {
return (
ember.isFunctionExpression(value) ||

@@ -30,5 +41,7 @@ types.isLiteral(value) ||

types.isMemberExpression(value) ||
types.isUnaryExpression(value)
types.isUnaryExpression(value) ||
isAllowedTernary(value) ||
isAllowedLogicalExpression(value)
);
};
}

@@ -80,3 +93,3 @@ //------------------------------------------------------------------------------

.forEach(property => {
if (!isAllowed(property)) {
if (!isAllowed(property.value)) {
report(property);

@@ -83,0 +96,0 @@ }

@@ -27,6 +27,6 @@ 'use strict';

* Checks if a LogicalExpression looks like `this.x && this.y && this.z`
* containing only simple `this.x` MemberExpression nodes.
* containing only simple `this.x` MemberExpression or `this.get('x')` CallExpression nodes.
*
* @param {Node} node The LogicalExpression node to check.
* @returns {boolean} Whether the node looks like `this.x && this.y && this.z`.
* @returns {boolean} Whether the node looks like `this.x && this.y && this.z` or `this.get('x') && this.get('y') && this.get('z')`.
*/

@@ -58,3 +58,3 @@ function isSimpleThisExpressionsInsideLogicalExpression(node, operator) {

/**
* Converts a simple LogicalExpression into an array of the MemberExpression nodes in it.
* Converts a simple LogicalExpression into an array of the MemberExpression/CallExpression nodes in it.
*

@@ -64,4 +64,4 @@ * Example Input: A LogicalExpression node with this source: `this.x && this.y.z && this.w`

*
* @param {Node} node The LogicalExpression node containing nodes that look like `this.x`.
* @returns {Node[]} An array of MemberExpression nodes contained in the LogicalExpression.
* @param {Node} node The LogicalExpression node containing nodes that look like `this.x` or `this.get('x')`.
* @returns {Node[]} An array of MemberExpression/CallExpression nodes contained in the LogicalExpression.
*/

@@ -68,0 +68,0 @@ function getThisExpressions(nodeLogicalExpression) {

const types = require('./types');
/**
* Checks if a MemberExpression node looks like `this.x` or `this.x.y`.
* Checks if a CallExpression node looks like `this.get('property')`.
*
* @param {Node} node The CallExpression node to check.
* @returns {boolean} Whether the node looks like `this.get('property')`.
*/
function isThisGetCall(node) {
if (
types.isCallExpression(node) &&
types.isMemberExpression(node.callee) &&
types.isThisExpression(node.callee.object) &&
types.isIdentifier(node.callee.property) &&
node.callee.property.name === 'get' &&
node.arguments.length === 1 &&
types.isStringLiteral(node.arguments[0])
) {
// Looks like: this.get('property')
return true;
}
return false;
}
/**
* Checks if a MemberExpression node looks like `this.x` or `this.x.y` or `this.get('x')`.
*
* @param {Node} node The MemberExpression node to check.
* @returns {boolean} Whether the node looks like `this.x` or `this.x.y`.
* @returns {boolean} Whether the node looks like `this.x` or `this.x.y` or `this.get('x')`.
*/
function isSimpleThisExpression(node) {
if (isThisGetCall(node)) {
return true;
}
if (!types.isMemberExpression(node)) {

@@ -34,9 +61,14 @@ return false;

*
* Example Input: A Node with this source code: `this.x.y`
* Example Input: A Node with this source code: `this.x.y` or `this.get('x')`
* Example Output: 'x.y'
*
* @param {Node} node a MemberExpression node that looks like `this.x` or `this.x.y`.
* @param {Node} node a MemberExpression node that looks like `this.x.y` or `this.get('x')`.
* @returns {String} The dependent key of the input node (without `this.`).
*/
function nodeToDependentKey(nodeWithThisExpression, context) {
if (types.isCallExpression(nodeWithThisExpression)) {
// Looks like: this.get('property')
return nodeWithThisExpression.arguments[0].value;
}
const sourceCode = context.getSourceCode();

@@ -47,4 +79,5 @@ return sourceCode.getText(nodeWithThisExpression).replace(/^this\./, '');

module.exports = {
nodeToDependentKey,
isSimpleThisExpression,
nodeToDependentKey,
isThisGetCall,
};
{
"name": "eslint-plugin-ember",
"version": "7.4.0",
"version": "7.4.1",
"description": "Eslint plugin for Ember.js apps",

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

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