Giter Site home page Giter Site logo

semgrep-rules's Introduction

Frappe Semgrep rules

Semgrep rules specific to Frappe Framework

These rules guard against typical mistakes or bad practices while working on Frappe Framework apps. Frappe's own apps also use this to simplify repetitive checks in code review process.

How to Use in my app

Github Action

You can use a GitHub Action to automatically validate changes with semgrep rules on all PRs.

name: Linters

on:
  pull_request: { }

jobs:
  linters:
    name: Frappe Linter
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'

      - name: Download Semgrep rules
        run: git clone --depth 1 https://github.com/frappe/semgrep-rules.git frappe-semgrep-rules

      - name: Download semgrep
        run: pip install semgrep

      - name: Run Semgrep rules
        run: semgrep ci --config ./frappe-semgrep-rules/rules

Manually / running semgrep locally

  • Install and verify that semgrep works semgrep --version
  • clone the rules repository git clonse
  • Run semgrep specifying rules folder as config semgrep --config=~/path/to/frappe-semgrep-rules/rules your_app_folder

Tip: You can optionally pass --severity=ERROR to ignore rules that produce warnings and only catch errors.

How to contribute new rules

semgrep-rules's People

Contributors

ankush avatar barredterra avatar gangamanoj avatar gavindsouza avatar phot0n avatar sagarvora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

semgrep-rules's Issues

Semgrep error when iterating one and appending to another table.

Imagine having 2 child table and looping over the first one and appending to the second table in each iteration. Semgrep will throw frappe-modifying-child-tables-while-iterating error.

- id: frappe-modifying-child-tables-while-iterating
  pattern-either:
    - pattern: |
        for $ROW in self.$TABLE:
            ...
            self.remove(...)
    - pattern: |
        for $ROW in self.$TABLE:
            ...
            self.append(...)
  message: |
      Child table being modified while iterating on it.
  languages: [python]
  severity: ERROR
  paths:
      include:
        - "*/**/doctype/*"

Column labels don't have to be translatable

Assuming you want to translate the source string to the target language only once (and not re-translate the translation), the rules in https://github.com/frappe/semgrep-rules/blob/c0a1c4fcc4eb9fd7813187fa2420872cba8a3770/rules/report.py seem to be incorrect. Report column labels should not be translated in the backend since they will get translated in the frontend anyway.

One argument for this rule would be to mark translatable strings. But then the translation function will be run twice, what brings its own problems.

@ankush can we remove these rules? Or maybe the better way would be to remove the second translation in the frontend?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.