Skip to content
No description, website, or topics provided.
JavaScript TypeScript
Branch: master
Clone or download
rwjblue Add link to `ember/no-get` lint rule in README (#27)
Add link to `ember/no-get` lint rule in README
Latest commit 358cd26 Dec 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
transforms/es5-getter-ember-codemod fix #15 Jun 14, 2019
.editorconfig fix #15 Jun 14, 2019
.eslintrc.js Initial Commit Feb 6, 2018
.gitignore Initial Commit Feb 6, 2018
.travis.yml Update .travis.yml Sep 1, 2018
README.md
package.json Add recast as a dependency Sep 1, 2018
yarn.lock Add recast as a dependency Sep 1, 2018

README.md

es5-getter-ember-codemod

Build Status

This codemod is intended to automatically convert your usage of get, and getProperties to use traditional object dot notation as proposed by emberjs/rfcs#281.

Special thanks to @rwjblue, @iezer, and @tbieniek for reviewing my original test cases.

Installation

es5-getter-ember-codemod itself doesn't need to be installed but you can run it using:

npx github:ember-codemods/es5-getter-ember-codemod ...

Usage

You can clone/download this repository or just run the codemods using the command shown in the following example:

npx github:ember-codemods/es5-getter-ember-codemod es5-getter-ember-codemod app/**/*.js

Transforms

foo.get('bar') -> foo.bar

Transforms get() method calls on objects (only for this and variables called controller or route).

Before:

this.get('fullName');

controller.get('fullName');

model.get('fullName');

route.get('fullName');

After:

this.fullName;

controller.fullName;

model.get('fullName');

route.fullName;

Ember.get(foo, 'bar') -> foo.bar

Transforms Ember.get() (or get() from @ember/object) calls (only for this as first argument).

Before:

import Ember from 'ember';
import { get } from '@ember/object'

let foo = get(this, 'foo');
let foo = get(this, 'foo.bar');

let foo = Ember.get(this, 'foo');
let foo = Ember.get(this, 'foo.bar');

let obj = { bar: 'baz' };
let bar = get(obj, 'bar');

After:

import Ember from 'ember';
import { get } from '@ember/object'

let foo = this.foo;
let foo = get(this, 'foo.bar');

let foo = this.foo;
let foo = Ember.get(this, 'foo.bar');

let obj = { bar: 'baz' };
let bar = get(obj, 'bar');

let { bar, baz } = foo.getProperties('bar', 'baz') -> let { bar, baz } = this

Transforms getProperties() method calls on objects (only for destructuring operations and not for nested paths).

Before:

let { foo, bar, baz } = this.getProperties('foo', 'bar', 'baz');

let { foo, barBaz } = this.getProperties('foo', 'bar.baz');

After:

let { foo, bar, baz } = this;

let { foo, barBaz } = this.getProperties('foo', 'bar.baz');

Enforcement

The ember/no-get lint rule is available for enforcing this.

You can’t perform that action at this time.