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

Add npm run quality script, Update Readme #97

Merged
merged 4 commits into from
Oct 31, 2018

Conversation

mukkachaitanya
Copy link
Collaborator

Requirements

  • Need for easy and better checks for code quality.

Description of the Change

Adds npm run quality script that uses eslint, jsinspect and buddy.js to keep a check on the quality of the project.

Benefits

Improved and easy code quality checking.

Applicable Issues

Addresses #96

@codecov
Copy link

codecov bot commented Oct 19, 2018

Codecov Report

Merging #97 into dev will decrease coverage by 1.41%.
The diff coverage is 88.15%.

Impacted file tree graph

@@           Coverage Diff            @@
##            dev      #97      +/-   ##
========================================
- Coverage   100%   98.58%   -1.42%     
========================================
  Files        21       22       +1     
  Lines       591      635      +44     
========================================
+ Hits        591      626      +35     
- Misses        0        9       +9
Flag Coverage Δ
#integration 95.74% <88.15%> (-1.21%) ⬇️
#unit 97.79% <86.84%> (-2.04%) ⬇️
Impacted Files Coverage Δ
lib/cli/input/init.js 100% <ø> (ø) ⬆️
lib/cli/output/exit.js 90% <0%> (-10%) ⬇️
lib/model/prefs.js 100% <100%> (ø) ⬆️
lib/controller/index.js 100% <100%> (ø)
lib/model/init.js 100% <100%> (ø) ⬆️
lib/utils/logger.js 100% <100%> (ø) ⬆️
lib/cli/input/eval.js 100% <100%> (ø) ⬆️
lib/utils/command-validator.js 100% <100%> (ø) ⬆️
lib/model/eval.js 97.56% <66.66%> (-2.44%) ⬇️
lib/cli/input/prefs.js 96.82% <75%> (-3.18%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff0d6a0...417c17c. Read the comment docs.

Copy link
Member

@prasadtalasila prasadtalasila left a comment

Choose a reason for hiding this comment

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

@mukkachaitanya please see the suggested changes.

package.json Outdated
@@ -9,7 +9,8 @@
"integration": "nyc --reporter=lcov --reporter=text-lcov -s --all mocha 'test/integration/**/*.js'",
"post-integration": "nyc report --reporter=lcov > coverage.lcov && codecov -F integration && rm -rf ~/.autolabjs",
"feature": "nyc --reporter=lcov --reporter=text-lcov -s --all cucumber-js 'test/feature/features' -r 'test/feature/steps'",
"post-feature": "nyc report --reporter=lcov > coverage.lcov && codecov -F feature"
"post-feature": "nyc report --reporter=lcov > coverage.lcov && codecov -F feature",
"quality" : "eslint . & jsinspect . & buddy ."
Copy link
Member

Choose a reason for hiding this comment

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

now the style is to put a comma even on the last line so that the diff shows modification only on one line.

Copy link
Member

Choose a reason for hiding this comment

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

"quality" : "eslint . && jsinspect . && buddy ."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sir, if eslint fails the none of the further checks are taken, i.e., none of jsinspect/buddy commands are executed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also sir, json doesn't accept a trailing comma. Throws the following error :

npm ERR! JSON.parse Unexpected token } in JSON at position 831 while parsing near '...ect . & buddy .",
npm ERR! JSON.parse   },
npm ERR! JSON.parse   "bin": {
npm ERR! JSON.parse     "a...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

@@ -1,5 +1,9 @@
{
"extends": "airbnb-base",
"env" : {
Copy link
Member

Choose a reason for hiding this comment

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

why are these needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

eslint give errors of the form :

12:3   error  'it' is not defined                                            no-undef
18:3   error  'describe' is not defined                                      no-undef

when mocha env is not set to be true.

.jsinspectrc Outdated
@@ -0,0 +1,8 @@
{
"threshold": 60,
Copy link
Member

Choose a reason for hiding this comment

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

This is not similar to codeclimate duplication weight. This number is the number of lines. A prudent value seems to be between 4 to 6.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll make that change.

@prasadtalasila
Copy link
Member

@mukkachaitanya also it is better to run npm quality command in the travis after the tests run successfully.

@mukkachaitanya
Copy link
Collaborator Author

Also Sir, there are a lot of eslint errors which have to be taken care of. I don't see codeclimate reporting them.

@mukkachaitanya mukkachaitanya force-pushed the code-quality branch 2 times, most recently from 6384353 to 254c706 Compare October 19, 2018 08:16
@prasadtalasila
Copy link
Member

Also Sir, there are a lot of eslint errors which have to be taken care of. I don't see codeclimate reporting them.

This is rude awakening for me as well. Please fix these issues before we do further development. One hypersensitive check is the threshold parameter in .jsinspectrc. This number can be increased to 20.

@mukkachaitanya
Copy link
Collaborator Author

mukkachaitanya commented Oct 26, 2018

Some changes in commit 6db57af to be considered :

  • Added buddyrc file to configure the buddy.js tool, which ignores [0, 1, 2, 3] as constants as we use them in the array indexing.
  • The threshold for jsinspect has been changed to the default value 30 as it was reporting issuses which we discussed to not to be limit.
  • The following rule was modified to allow the usage of unary ++ or -- operators in loops only.
"no-plusplus" : ["error", { "allowForLoopAfterthoughts": true }],
  • Also, the following rule was added to take care of issues arising from cumumber.js tests
"no-unused-vars": [
            "error",
            {
              "varsIgnorePattern": "should|expect|Before|After|Given"
            }
        ]
  • The following rule also switches of max-lines-per-function in the unit tests
 "max-lines-per-function" : ["off"]
  • Also the the rule no-reassign-param has been switched off in some places especially in the integration test. (for example, test/integration/eval.js)

.buddyrc Outdated
{
"detectObjects": false,
"enforceConst": false,
"ignore": [0, 1, 2, 3],
Copy link
Member

Choose a reason for hiding this comment

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

please remove this ignore statement.

.buddyrc Outdated
@@ -0,0 +1,6 @@
{
"detectObjects": false,
Copy link
Member

Choose a reason for hiding this comment

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

please clarify the use of next two lines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to the documentation :

detectObjects    -    detect object expressions and properties
enforceConst     -    require literals to be defined using const

I think we can switch both to true.

.eslintrc Outdated
"node": true,
"mocha": true
},
"rules": {
Copy link
Member

Choose a reason for hiding this comment

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

please clarify the reason for using the rule.

.eslintrc Outdated
"no-unused-vars": [
"error",
{
"varsIgnorePattern": "should|expect|Before|After|Given"
Copy link
Member

Choose a reason for hiding this comment

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

avoid this rule using a plug-in?

@@ -37,9 +41,9 @@ const printTableAndGetScore = (data) => {
};

const printStatusAndLog = (data, totalScore) => {
logger.moduleLog('debug', 'Eval Output', `Evaluation logs: ${new Buffer(data.log, 'base64').toString()}.`);
logger.moduleLog('debug', 'Eval Output', `Evaluation logs: ${Buffer.from(data.log, 'base64').toString()}.`);
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Buffer constructor is different depending on the type of its argument, and not validating such arguments might lead to memory disclosure and denial of service. So eslint enforces the use of Buffer.from() or Buffer.alloc() instead.

ref

if (!type) {
const typePrompt = prefPrompts.getServerTypePrompt();
type = (await inquirer.prompt(typePrompt)).type;
({ type } = (await inquirer.prompt(typePrompt)));
Copy link
Member

Choose a reason for hiding this comment

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

why brackets?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have discussed this, sir, but for having everything in a single thread; the MDN documentation says:

The parentheses ( ... ) around the assignment statement are required when using object literal destructuring assignment without a declaration.

{a, b} = {a: 1, b: 2} is not valid stand-alone syntax, as the {a, b} on the left-hand side is considered a block and not an object literal.

However, ({a, b} = {a: 1, b: 2}) is valid, as is var {a, b} = {a: 1, b: 2}

NOTE: Your ( ... ) expression needs to be preceded by a semicolon or it may be used to execute a function on the previous line.

@@ -77,7 +80,7 @@ const storePrefs = (changePrefEvent) => {
} else if (changePrefEvent.name === 'server_changed') {
storeServer(changePrefEvent.details);
} else if (changePrefEvent.name === 'show_prefs') {
changePrefEvent = eventForShowPref(changePrefEvent);
return eventForShowPref(changePrefEvent);
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The function storePrefs was modifying the input argument changePrefEvent storing and then returning it. Instead, the above modification returns the new value directly.

package.json Outdated
@@ -9,7 +9,8 @@
"integration": "nyc --reporter=lcov --reporter=text-lcov -s --all mocha 'test/integration/**/*.js'",
"post-integration": "nyc report --reporter=lcov > coverage.lcov && codecov -F integration && rm -rf ~/.autolabjs",
"feature": "nyc --reporter=lcov --reporter=text-lcov -s --all cucumber-js 'test/feature/features' -r 'test/feature/steps'",
"post-feature": "nyc report --reporter=lcov > coverage.lcov && codecov -F feature"
"post-feature": "nyc report --reporter=lcov > coverage.lcov && codecov -F feature",
"quality": "eslint . & jsinspect . & buddy ."
Copy link
Member

Choose a reason for hiding this comment

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

please add &&

@@ -1,3 +1,4 @@
/* eslint no-use-before-define: "warn" */
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to refactor the cyclic functions.

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