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

Fix linter script to run all tags #3400

Merged
merged 2 commits into from
Jul 11, 2018
Merged

Conversation

sarangan12
Copy link
Member

@sarangan12 sarangan12 commented Jul 11, 2018

This checklist is used to make sure that common issues in a pull request are addressed. This will expedite the process of getting your pull request merged and avoid extra work on your part to fix issues discovered during the review process.

PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • Except for special cases involving multiple contributors, the PR is started from a fork of the main repository, not a branch.
  • If applicable, the PR references the bug/issue that it fixes.
  • Swagger files are correctly named (e.g. the api-version in the path should match the api-version in the spec).

Quality of Swagger

@AutorestCI
Copy link

AutorestCI commented Jul 11, 2018

Automation for azure-sdk-for-node

Unable to detect any generation context from this PR.

@AutorestCI
Copy link

AutorestCI commented Jul 11, 2018

Automation for azure-sdk-for-java

Unable to detect any generation context from this PR.

@AutorestCI
Copy link

AutorestCI commented Jul 11, 2018

Automation for azure-sdk-for-go

Unable to detect any generation context from this PR.

@AutorestCI
Copy link

AutorestCI commented Jul 11, 2018

Automation for azure-sdk-for-ruby

Unable to detect any generation context from this PR.

@AutorestCI
Copy link

AutorestCI commented Jul 11, 2018

Automation for azure-sdk-for-python

Unable to detect any generation context from this PR.

@sarangan12
Copy link
Member Author

@veronicagg @salameer FYI.....

test/linter.js Outdated
@@ -116,15 +122,21 @@ describe('AutoRest Linter validation:', function () {
return prFile.startsWith(configDir) && prFile.indexOf('examples') === -1 && prFile.endsWith('.json');
}).forEach(prFileInConfigFile => {
console.warn(`WARNING: Configuration file not found for file: ${prFileInConfigFile}, running validation rules against it in individual context.`);
execLinterCommand(`--input-file=${prFileInConfigFile}`);
errorsFound = errorsFound && execLinterCommand(`--input-file=${prFileInConfigFile}`);
Copy link

@vladbarosan vladbarosan Jul 11, 2018

Choose a reason for hiding this comment

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

execLinterCommand will never execute since errorsFound is always false right ?

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense. But surprisingly it was executing all 3 tags during my testing. hmm....

Just to be on the safe side, I have rearranged the order.

test/linter.js Outdated
@@ -102,6 +105,9 @@ describe('AutoRest Linter validation:', function () {

// find all tags in the config file
const tagsToProcess = await getTagsFromConfig(config);

var errorsFound = false;

Choose a reason for hiding this comment

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

let not var

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Done

try {
let result = execSync(cmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 });
console.error(result);
} catch (err) {
throw new Error('Linter validation contains error(s)');
errorsFound = true;
console.error('Linter validation contains error(s)');

Choose a reason for hiding this comment

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

print the error also ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The Linter itself will print the error. So, printing it again is not required.

try {
let result = execSync(cmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 });
console.error(result);
} catch (err) {
throw new Error('Linter validation contains error(s)');
errorsFound = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

@sarangan12 I know we talked a bit offline, but could you provide details on the PR on the bug you're trying to fix? - like what issue you found and how it's not working with the current code.

@dsgouda I believe we worked on adding looping through tags a while back and can't remember why we decided to exit early, do you?

Copy link
Member Author

Choose a reason for hiding this comment

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

Created an issue and provided a detailed explanation and also linked the issue with this PR

test/linter.js Outdated
@@ -116,15 +122,21 @@ describe('AutoRest Linter validation:', function () {
return prFile.startsWith(configDir) && prFile.indexOf('examples') === -1 && prFile.endsWith('.json');
}).forEach(prFileInConfigFile => {
console.warn(`WARNING: Configuration file not found for file: ${prFileInConfigFile}, running validation rules against it in individual context.`);
execLinterCommand(`--input-file=${prFileInConfigFile}`);
errorsFound = errorsFound && execLinterCommand(`--input-file=${prFileInConfigFile}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be an OR statement? same below

Choose a reason for hiding this comment

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

well with OR we would just have the old behavior ( once it founds errors it would stop processing further ). I think the intention of the processing to continue. In that case just execute the command seperatley and && on the result

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, if you put ||, it will still continue executing all the tags. But, the job itself will be marked as success irrespective of presence of the errors. We do not want to do that. That is the reason for &&.

Choose a reason for hiding this comment

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

why will it continue ? if we put || once errorsFound becomes true ( i.e. one of them fails) then it will not execute execLinterCommand because of the shortcircuit logic right ? ( for files here for tags afterwards )

@@ -82,13 +82,16 @@ async function getTagsFromConfig(config) {
function execLinterCommand(args) {
var cmd = `npx autorest@2.0.4152 --validation --azure-validator --message-format=json ${args}`.trim();

Choose a reason for hiding this comment

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

we should just use autorest as a library and call the linter through it

Choose a reason for hiding this comment

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

we use autorest as a library in the tooling service you can have a look there how to do it, that way also we wont have the autorest version hardcoded in the file

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. I will look into it and take it up as a seperate issue.

@hovsepm
Copy link
Contributor

hovsepm commented Jul 11, 2018

I have no background or information about linter. Reassigning to @veronicagg

@sarangan12
Copy link
Member Author

Addressed the comments. Merging it now

@sarangan12 sarangan12 merged commit d848622 into Azure:master Jul 11, 2018
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.

5 participants