Skip to content

JS-605 Update rules from 'All' -> 'Main' #4952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged

JS-605 Update rules from 'All' -> 'Main' #4952

merged 1 commit into from
Apr 14, 2025

Conversation

zglicz
Copy link
Contributor

@zglicz zglicz commented Apr 11, 2025

JS-605

Currently, we only support rules being either 'Main' or 'Test'. If a rule is set to be 'All', we default it to 'Main'. This is probably not what we want to do in the long run, but for now, this is the truth about what is happening behind the scenes.
Later, we might want to check the scope of the parent rule, if it is 'All', perhaps we might want to re-enable it for both 'Main' and 'Tests' ('All') in our rule as well.

Script used to make this update:

import * as path from 'path';

const directoryPath = './rules'; // Replace with your directory path

function readDirectory(directory: string): void {
    readdir(directory, (err, files) => {
        if (err) {
            console.error('Error reading directory:', err);
            return;
        }

        files.forEach(file => {
            const filePath = path.join(directory, file);
            stat(filePath, (err, stats) => {
                if (err) {
                    console.error('Error getting file stats:', err);
                    return;
                }

                if (stats.isDirectory()) {
                    readRuleFolder(filePath);
                }
            });
        });
    });
}

function readRuleFolder(folderPath: string): void {
    readdir(folderPath, (err, files) => {
        if (err) {
            console.error('Error reading javascript folder:', err);
            return;
        }

        // console.log(`Contents of rule folder:`, files);
        files.forEach(folder => {
            if (folder === 'javascript') {
                // read javascript json
                const jsMetadataPath = path.join(folderPath, folder, 'metadata.json');
                let jsContents = JSON.parse(readFileSync(jsMetadataPath, 'utf-8'));
                let ruleContents = JSON.parse(readFileSync(path.join(folderPath, 'metadata.json'), 'utf-8'));

                const derivedScope = (jsContents.scope ?? ruleContents.scope);
                if (derivedScope === 'All') {
                    console.log(folderPath, derivedScope);
                    jsContents.scope = 'Main';
                    writeFileSync(jsMetadataPath, JSON.stringify(jsContents, null, 2));
                }
            }
        });
    });
}

readDirectory(directoryPath);
console.log('running');```

[JS-605]: https://sonarsource.atlassian.net/browse/JS-605?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

@zglicz zglicz added the javascript Pull requests that update Javascript code label Apr 11, 2025
@zglicz zglicz requested a review from a team April 11, 2025 08:42
Copy link

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link
Contributor

@vdiez vdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vdiez vdiez added this pull request to the merge queue Apr 14, 2025
Merged via the queue into master with commit 8a892cb Apr 14, 2025
12 of 13 checks passed
@vdiez vdiez deleted the JS-605 branch April 14, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants