Skip to content

Latest commit

 

History

History
600 lines (417 loc) · 10.2 KB

File metadata and controls

600 lines (417 loc) · 10.2 KB

argument-decorators-cleanup

Usage

npx @ember-decorators/argument-codemod argument-decorators-cleanup path/of/files/ or/some**/*glob.js

# or

yarn global add @ember-decorators/argument-codemod
@ember-decorators/argument-codemod argument-decorators-cleanup path/of/files/ or/some**/*glob.js

Local Usage

node ./bin/cli.js argument-decorators-cleanup path/of/files/ or/some**/*glob.js

Input / Output


argument-decorators-with-defaults

Input (argument-decorators-with-defaults.input.js):

import {
  Action,
  ClassicAction,
  Element,
  Node
} from '@ember-decorators/argument/types';

class MyClass {}
const myClassInstance = new MyClass();

class Foo extends Component {
  /**
   * A multi-line comment
   * @type {'any'}
   */
  @someOtherDecorator
  @someOtherDecoratorFunction('yo')
  @argument('any')
  anyArgument = NaN;

  // Single line comment
  @argument('boolean')
  booleanArgument = true;

  @argument('null')
  nullArgument = null;

  @argument('number')
  numberArgument = 1;

  @argument('object')
  objectArgument = {};

  @argument('string')
  stringArgument = '';

  @argument('symbol')
  symbolArgument = Symbol();

  @argument('undefined')
  undefinedArgument = undefined;

  @argument(Action)
  actionArgument = () => {};

  @argument(ClassicAction)
  classicActionArgument = 'myAction';

  @argument(Element)
  elementArgument = window.Element;

  @argument(Node)
  nodeArgument = window.Node;

  @argument(MyClass)
  classArgument = myClassInstance;

  @argument(optional(Date))
  optionalArgument = new Date();

  @argument(arrayOf('string'))
  arrayArgument = ['one', 'two', 'three'];

  @argument(oneOf('red', 'blue', 'yellow'))
  oneArgument = 'blue';

  @argument(shapeOf({ id: 'string' }))
  shapeArgument = { id: 'hello' };

  @argument(unionOf('number', 'string'))
  unionArgument = '1';

  @argument(unionOf('string', shapeOf({ id: optional('string') })))
  nestedArgument = { id: '1' };
}

Output (argument-decorators-with-defaults.output.js):

class MyClass {}
const myClassInstance = new MyClass();

class Foo extends Component {
  /**
   * A multi-line comment
   * @type {'any'}
   */
  @someOtherDecorator
  @someOtherDecoratorFunction('yo')
  anyArgument = NaN;

  // Single line comment
  booleanArgument = true;

  nullArgument = null;

  numberArgument = 1;

  objectArgument = {};

  stringArgument = '';

  symbolArgument = Symbol();

  undefinedArgument = undefined;

  actionArgument = () => {};

  classicActionArgument = 'myAction';

  elementArgument = window.Element;

  nodeArgument = window.Node;

  classArgument = myClassInstance;

  optionalArgument = new Date();

  arrayArgument = ['one', 'two', 'three'];

  oneArgument = 'blue';

  shapeArgument = { id: 'hello' };

  unionArgument = '1';

  nestedArgument = { id: '1' };
}

argument-decorators

Input (argument-decorators.input.js):

import {
  Action,
  ClassicAction,
  Element,
  Node
} from '@ember-decorators/argument/types';

class MyClass {}

class Foo extends Component {
  /**
   * A multi-line comment
   * @type {'any'}
   */
  @someOtherDecorator
  @someOtherDecoratorFunction('yo')
  @argument('any')
  anyArgument;

  // Single line comment
  @argument('boolean')
  booleanArgument;

  @argument('null')
  nullArgument;

  @argument('number')
  numberArgument;

  @argument('object')
  objectArgument;

  @argument('string')
  stringArgument;

  @argument('symbol')
  symbolArgument;

  @argument('undefined')
  undefinedArgument;

  @argument(Action)
  actionArgument;

  @argument(ClassicAction)
  classicActionArgument;

  @argument(Element)
  elementArgument;

  @argument(Node)
  nodeArgument;

  @argument(MyClass)
  classArgument;

  @argument(optional(Date))
  optionalArgument;

  @argument(arrayOf('string'))
  arrayArgument;

  @argument(oneOf('red', 'blue', 'yellow'))
  oneArgument;

  @argument(shapeOf({ id: 'string' }))
  shapeArgument;

  @argument(unionOf('number', 'string'))
  unionArgument;

  @argument(unionOf('string', shapeOf({ id: optional('string') })))
  nestedArgument;
}

Output (argument-decorators.output.js):

class MyClass {}

class Foo extends Component {
  /**
   * A multi-line comment
   * @type {'any'}
   */
  @someOtherDecorator
  @someOtherDecoratorFunction('yo')
  anyArgument;

  // Single line comment
  booleanArgument;

  nullArgument;

  numberArgument;

  objectArgument;

  stringArgument;

  symbolArgument;

  undefinedArgument;

  actionArgument;

  classicActionArgument;

  elementArgument;

  nodeArgument;

  classArgument;

  optionalArgument;

  arrayArgument;

  oneArgument;

  shapeArgument;

  unionArgument;

  nestedArgument;
}

type-decorators-with-defaults

Input (type-decorators-with-defaults.input.js):

import {
  Action,
  ClassicAction,
  Element,
  Node
} from '@ember-decorators/argument/types';

class MyClass {}
const myClassInstance = new MyClass();

class Foo extends Component {
  /**
   * A multi-line comment
   * @type {'any'}
   */
  @someOtherDecorator
  @someOtherDecoratorFunction('yo')
  @argument
  @type('any')
  anyArgument = NaN;

  // Single line comment
  @argument
  @type('boolean')
  booleanArgument = true;

  @argument
  @type('null')
  nullArgument = null;

  @argument
  @type('number')
  numberArgument = 1;

  @argument
  @type('object')
  objectArgument = {};

  @argument
  @type('string')
  stringArgument = '';

  @argument
  @type('symbol')
  symbolArgument = Symbol();

  @argument
  @type('undefined')
  undefinedArgument = undefined;

  @argument
  @type(Action)
  actionArgument = () => {};

  @argument
  @type(ClassicAction)
  classicActionArgument = 'myAction';

  @argument
  @type(Element)
  elementArgument = window.Element;

  @argument
  @type(Node)
  nodeArgument = window.Node;

  @argument
  @type(MyClass)
  classArgument = myClassInstance;

  @argument
  @type(optional(Date))
  optionalArgument = new Date();

  @argument
  @type(arrayOf('string'))
  arrayArgument = ['one', 'two', 'three'];

  @argument
  @type(oneOf('red', 'blue', 'yellow'))
  oneArgument = 'blue';

  @argument
  @type(shapeOf({ id: 'string' }))
  shapeArgument = { id: 'hello' };

  @argument
  @type(unionOf('number', 'string'))
  unionArgument = '1';

  @argument
  @type(unionOf('string', shapeOf({ id: optional('string') })))
  nestedArgument = { id: '1' };
}

Output (type-decorators-with-defaults.output.js):

class MyClass {}
const myClassInstance = new MyClass();

class Foo extends Component {
  /**
   * A multi-line comment
   * @type {'any'}
   */
  @someOtherDecorator
  @someOtherDecoratorFunction('yo')
  anyArgument = NaN;

  // Single line comment
  booleanArgument = true;

  nullArgument = null;

  numberArgument = 1;

  objectArgument = {};

  stringArgument = '';

  symbolArgument = Symbol();

  undefinedArgument = undefined;

  actionArgument = () => {};

  classicActionArgument = 'myAction';

  elementArgument = window.Element;

  nodeArgument = window.Node;

  classArgument = myClassInstance;

  optionalArgument = new Date();

  arrayArgument = ['one', 'two', 'three'];

  oneArgument = 'blue';

  shapeArgument = { id: 'hello' };

  unionArgument = '1';

  nestedArgument = { id: '1' };
}

type-decorators

Input (type-decorators.input.js):

import {
  Action,
  ClassicAction,
  Element,
  Node
} from '@ember-decorators/argument/types';

class MyClass {}

class Foo extends Component {
  @someOtherDecorator
  @someOtherDecoratorFunction('yo')
  @argument
  @type('any')
  anyArgument;

  @argument
  @type('boolean')
  booleanArgument;

  @argument
  @type('null')
  nullArgument;

  @argument
  @type('number')
  numberArgument;

  @argument
  @type('object')
  objectArgument;

  @argument
  @type('string')
  stringArgument;

  @argument
  @type('symbol')
  symbolArgument;

  @argument
  @type('undefined')
  undefinedArgument;

  @argument
  @type(Action)
  actionArgument;

  @argument
  @type(ClassicAction)
  classicActionArgument;

  @argument
  @type(Element)
  elementArgument;

  @argument
  @type(Node)
  nodeArgument;

  @argument
  @type(MyClass)
  classArgument;

  @argument
  @type(optional(Date))
  optionalArgument;

  @argument
  @type(arrayOf('string'))
  arrayArgument;

  @argument
  @type(oneOf('red', 'blue', 'yellow'))
  oneArgument;

  @argument
  @type(shapeOf({ id: 'string' }))
  shapeArgument;

  @argument
  @type(unionOf('number', 'string'))
  unionArgument;

  @argument
  @type(unionOf('string', shapeOf({ id: optional('string') })))
  nestedArgument;
}

Output (type-decorators.output.js):

class MyClass {}

class Foo extends Component {
  @someOtherDecorator
  @someOtherDecoratorFunction('yo')
  anyArgument;

  booleanArgument;

  nullArgument;

  numberArgument;

  objectArgument;

  stringArgument;

  symbolArgument;

  undefinedArgument;

  actionArgument;

  classicActionArgument;

  elementArgument;

  nodeArgument;

  classArgument;

  optionalArgument;

  arrayArgument;

  oneArgument;

  shapeArgument;

  unionArgument;

  nestedArgument;
}