devreplay
    TypeScript icon, indicating that this package has built-in type declarations

    1.11.1 • Public • Published

    Devreplay

    CI Lint

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

    How to use

    1. Install on local
    $ npm install -g 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": "Information"
    }
    • severity means how this rule is important

      • E: Error
      • W: Warning
      • I: Information
      • H: 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

    [
      "typescript",
      "react",
    ]

    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

    API Usage

    You can use devreplay as a TypeScript API.

    import {DevReplayRule, BaseRule2DevReplayRule, fixWithRules} from 'devreplay';
    
    const rules: DevReplayRule[] = [{
        before: [
          '([a-z]+)-([a-z]+)'
        ],
        after: [
            '$1 $2'
        ],
        isRegex: true
    },
    {
      before: [
        'for \\(let (?<i>.+) = 0;\\k<i> < (?<arr>.+).length;\\k<i>\\+\\+\\) (.*)\\(\\k<arr>\\[\\k<i>\\]\\)'
      ],
      after: [
        'for (let $1 = 0;$1 < $2.length;i++) {',
        '    $3($2[$1])',
        '}'
      ],
      isRegex: true,
      message: 'One line for should use paren'
    }].map(rule => BaseRule2DevReplayRule(rule, 0));
    
    const fixed = fixWithRules('print("hello-world")', rules)
    /*
    'print("hello world")'
    */
    console.log(fixed)
    
    const fixed2 = fixWithRules('for (let i = 0;i < arr.length;i++) foo(arr[i])', rules)
    /*
    for (let i = 0;i < arr.length;i++) {
      foo(arr[i])
    }
    */
    console.log(fixed2)

    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

    Contribution Link

    License

    MIT © 2019 Yuki Ueda ikuyadeu0513@gmail.com (ikuyadeu.github.io)

    Install

    npm i devreplay

    DownloadsWeekly Downloads

    315

    Version

    1.11.1

    License

    MIT

    Unpacked Size

    185 kB

    Total Files

    122

    Last publish

    Collaborators

    • ikuyadeu