Revision d950d2456ef1515578fed1bfaf3b816797de9e8e authored by Roman Donchenko on 28 June 2023, 20:26:24 UTC, committed by GitHub on 28 June 2023, 20:26:24 UTC
<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->
This was broken in 4fc494f4.

Add a test to cover this case.

Fixes #6047.
1 parent 1b28162
Raw File
lint-staged.config.js
// lint-staged.config.js

const micromatch = require('micromatch');

function containsInPath(pattern, list) {
    return list.filter((item) => micromatch.contains(item, pattern));
}

function makePattern(extension) {
    return `**/*.${extension}`;
}

module.exports = (stagedFiles) => {
    const eslintExtensions = ['ts', 'tsx', 'js'].map(makePattern);
    const scssExtensions = ['scss'].map(makePattern);
    const eslintFiles = micromatch(stagedFiles, eslintExtensions);
    const scssFiles = micromatch(stagedFiles, scssExtensions);

    const tests = containsInPath('/tests/cypress', eslintFiles);
    const cvatData = containsInPath('/cvat-data/', eslintFiles);
    const cvatCore = containsInPath('/cvat-core/src', eslintFiles);
    const cvatCanvas = containsInPath('/cvat-canvas/', eslintFiles);
    const cvatCanvas3d = containsInPath('/cvat-canvas3d/', eslintFiles);
    const cvatUI = containsInPath('/cvat-ui/', eslintFiles);

    const mapping = {};
    const commands = [];
    mapping['npx stylelint --fix '] = scssFiles.join(' ');
    mapping['yarn run precommit:cvat-tests -- '] = tests.join(' ');
    mapping['yarn run precommit:cvat-ui -- '] = cvatUI.join(' ');
    mapping['yarn run precommit:cvat-data -- '] = cvatData.join(' ');
    mapping['yarn run precommit:cvat-core -- '] = cvatCore.join(' ');
    mapping['yarn run precommit:cvat-canvas -- '] = cvatCanvas.join(' ');
    mapping['yarn run precommit:cvat-canvas3d -- '] = cvatCanvas3d.join(' ');

    for (const command of Object.keys(mapping)) {
        const files = mapping[command];
        if (files.length) {
            commands.push(`${command} ${files}`);
        }
    }

    return commands;
};
back to top