ShakaCode | ShakaCode Blog | Rails On Maui Blog | Rails | ReactJs | JavaScript | Webpack | Productivity |

Useful Regexps When Linting JavaScript and Converting to ES6


#1

Add the displayName property to react classes

Find

(var|const) (\w+) = React.createClass\(\{\n

Replace with:

const $2 = React.createClass({\n  displayName: '$2',\n

Change to function declaration from function expression

Find

(const|var) (\w+) = function\(

Replace with:

function $2(

Change var foo = require(“foo”); to import foo from “foo”;

Find

var (\w+) = require\((.*)\);

to

import $1 from $2;

Change foo[‘bar’][‘baz’] to foo.bar.baz

find

\['(\w+)'\]

replace with

.$1

Add at one blank line between properties separated by commas

Find

,\n

Replace

,\n\n

Object keys don’t use extra quotes

Instead of:

{
  'a': 123,
  'b': 456
}

use

{
  a: 123,
  b: 456
}

Replace

'(\w+)':

with

$1: