Skip to content
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

Lint command #31

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft

Lint command #31

wants to merge 25 commits into from

Conversation

disha-148
Copy link
Collaborator

No description provided.

if (!fs.existsSync(dashboardsPath) || !fs.statSync(dashboardsPath).isDirectory()) {
missingFiles.push('dashboards folder');
}
if (!readmeContent) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tab indent issue

console.error('README.md file content is empty or missing.');
missingFiles.push('README.md');
}
if (missingFiles.length > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tab indent issue

// Function to handle lint logic
async function handleLint(argv: any) {
const currentDirectory = process.cwd();
console.log(`Current working directory: ${currentDirectory}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably we shall use logger instead of console consistently throughout the lint function.

missingFiles.push('dashboards folder');
}
if (!readmeContent) {
console.error('README.md file content is empty or missing.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably we can omit such log output consistently since we will output the lint results at last.

}
if (missingFiles.length > 0) {
console.error(`Missing required files or folders: ${missingFiles.join(', ')}`);
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably should exit the program with -1 so that's friendly to integrate with pipeline that reports failures.

await validatePackageJson(packageData);

// Validate access rules in JSON files within the `dashboards` folder
validateAccessRulesInDashboards(dashboardsPath);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggest to rename it more general, in case we have more checks later with the dashboard files.

// Function to validate `package.json`
async function validatePackageJson(packageData: any): Promise<void> {
// Validate `name`
const namePattern = /^@instana-integration\/[a-zA-Z0-9-_]+$/;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This rule is only a must if the package is officially maintained by IBM. User defined package does not need to follow it. We can report it as a warning instead of error. Or we can make it configurable (error vs. warning), e.g.: when run lint against observability-as-code repo, we should enable it as error, since the repo is used to host official package.

if (!namePattern.test(packageData.name)) {
throw new Error(`Invalid package name "${packageData.name}". The name must start with "@instana-integration/" followed by the package name.`);
}
console.log('Package name is valid.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

These kind of logging info probably can be changed to use logger.debug.

}

// Check for description
if (!packageData.description) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks this can also be merged into the above code block for the required fields check.

const files = fs.readdirSync(dashboardsPath);
const jsonFiles = files.filter(file => file.endsWith('.json'));

if(jsonFiles.length === 0){
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's valid the dashboards folder is empty.

@@ -0,0 +1,618 @@
{
"id": "QlCHQaXSTs-j5CnOKPIrEQ",
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's this dashboard used for?

})
.option('debug', {
alias: 'd',
describe: 'Enable debug mode to show detailed logs',
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's debug option in other commands, just to be sure we have the same description consistently.

const requiredSections = [
packageName,
'Dashboards',
'Go Runtime Metrics',
Copy link
Collaborator

Choose a reason for hiding this comment

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

These titles are particularly for go, when it comes to other technology, title will be changed. We could think about using a set of consistent titles, e.g.: "Metrics", "Semantic Conventions".

}
} catch (error) {
if ((error as AxiosError).response?.status === 404) {
if (packageData.version === '1.0.0') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's a new package, can we just leave as is w/o restricting the init version?

// Validate `name`
const namePattern = /^@instana-integration\/[a-zA-Z0-9-_]+$/;
if (!namePattern.test(packageData.name)) {
warnings.push(`Warning: Package name "${packageData.name}" does not align with the IBM package naming convention.`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

When enabling this w/ pipeline to observability-as-code repo, can we enforce such warnings on the pipeline. This means if there's warning detected like this, we will fail the pipeline and report back to the associated PR. This is ensure user contributed contents align w/ the rules we defined for all the official packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants