Lint-staged: Possible to pass staged files as a comma-separated list?

Created on 15 Aug 2018  路  2Comments  路  Source: okonet/lint-staged

I have an analysis script (phan/phan) that I'd like to run on all my staged files. However, the way I'd do this would be with the command:

./vendor/bin/phan -p --include-analysis-file-list file1.php,file2.php,file3.php

... where fileX.php are the staged files.

If I set my lint-staged configuration like the following, then it only analyzes the first file, because lint-stage passes in the list of files space separated.

            "*.php": [
                "./vendor/bin/phan -p --include-analysis-file-list",
                "git add"
            ]

Is there a way to get a comma-separated list of the staged files instead? And, ideally, this would be configurable per linter (since I still want my eslint config to work).

Thanks!

Environment

  • OS: macOS High Sierra 10.13.6
  • Node.js: v9.11.1
  • lint-staged: 7.2.0
duplicate enhancement question

Most helpful comment

Sounds good.

For anyone searching and looking for a quick solution, this is what I implemented:

_package.json:_

"lint-staged": {
    "linters": {
        "*.php": [
            "./phan-wrapper.sh",
            "git add"
        ]
    }
}

_phan-wrapper.sh:_

# convert argument list to comma-separated string
OLDIFS=$IFS
IFS=","
CSV_FILES=$*
IFS=$OLDIFS

# run task
./vendor/bin/phan -p --include-analysis-file-list "${CSV_FILES}"

All 2 comments

That sounds like a duplicate of #138 to me. Please chime in and add your opinion. Plus we had this https://github.com/okonet/lint-staged/pull/221 but I'm not sure it's the right approach. Please review it and let us know what you think there.

Sounds good.

For anyone searching and looking for a quick solution, this is what I implemented:

_package.json:_

"lint-staged": {
    "linters": {
        "*.php": [
            "./phan-wrapper.sh",
            "git add"
        ]
    }
}

_phan-wrapper.sh:_

# convert argument list to comma-separated string
OLDIFS=$IFS
IFS=","
CSV_FILES=$*
IFS=$OLDIFS

# run task
./vendor/bin/phan -p --include-analysis-file-list "${CSV_FILES}"
Was this page helpful?
0 / 5 - 0 ratings