Devreplay is static analysis tool based on your own programming rule.

How to use

  1. Install on local
$ npm install devreplay
# or
$ yarn global add devreplay
  1. Put your own programming rule(.devreplay.json) on the project like bellow
[
  {
    "before": [
      "(?<tmp>.+)\\s*=\\s*(?<a>.+)",
      "\\k<a>\\s*=\\s*(?<b>.+)",
      "\\k<b>\\s*=\\s*\\k<tmp>"
    ],
    "after": [
      "$2, $3 = $3, $2"
    ],
    "isRegex": true
  }
]
  1. Run the devreplay
devreplay yourfile.py

or get fixed code

devreplay --fix yourfile.py > yourfile.py

The target source code file will be

- tmp = a
- a = b
- b = a
+ a, b = b, a
  • Step up: Make the rule message and severity. Also after can be more abstract
[
  {
    "before": [
      "(?<tmp>.+)\\s*=\\s*(?<a>.+)",
      "\\k<a>\\s*=\\s*(?<b>.+)",
      "\\k<b>\\s*=\\s*\\k<tmp>"
    ],
    "after": [
      "$2, $3 = $3, $2"
    ],
    "isRegex": true,
    "author": "Yuki Ueda",
    "message": "Value exchanging can be one line",
    "severity": "info"
  }
]
  • severity means how this rule is important
    • error
    • warning
    • info
    • hint
  • Run devreplay again
$ devreplay yourfile.py
./yourfile.py
  15:1  warning  Value exchanging can be one line  0

Also, you can use default rules by extends some rules such as

[
  "python"
]

Make rules by using Regular Expression

{
  "before": [
    "([a-z]+)-([a-z]+)"
  ],
  "after": [
      "$1 $2"
  ],
  "isRegex": true
}

That will fix

- print("hello-world")
+ print("hello world")

Support Languages and Frameworks

Languages Frameworks
C Android
CPP Angular
Cobol chainer2pytouch
Dart Rails
Java React
JavaScript TensorFlow
PHP  
Python  
Ruby  
TypeScript  
VS Code  
Vue  

GitHub Actions

Please copy following .github/workflows/devreplay.yml file to your repository.

name: Devreplay
on: [push, pull_request]
jobs:
  devreplay:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: "14.x"
      - run: npm install -g devreplay
      - name: Run devreplay
        run: devreplay ./ .devreplay.json