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

Standardjs installation and running #47

Merged
merged 11 commits into from
Oct 31, 2024
Merged

Standardjs installation and running #47

merged 11 commits into from
Oct 31, 2024

Conversation

lexik04
Copy link

@lexik04 lexik04 commented Oct 23, 2024

Installation

Screenshot 2024-10-23 at 3 08 36 PM

Example Code that breaks many rules(Generated by chatGPT)

function add(a, b) {
    return a + b
  }
  
  function isEven(num) {
    return num % 2 === 0
  }
  

  const numbers = [1, 2, 3, 4, 5]
  const evenNumbers = numbers.filter(isEven)
  
  console.log('Even numbers:', evenNumbers)
  

  for (let i = 0; i < numbers.length; i++) {
    console.log(`Number ${numbers[i]} is ${isEven(numbers[i]) ? 'even' : 'odd'}`)
  }

Test:

lexikronowitz@lexis-air nodebb-f24-team-tbd-1 % npx standard test/standardjs.js
standard: Use JavaScript Standard Style (https://standardjs.com)
standard: Run `standard --fix` to automatically fix some problems.
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:2:10: 'add' is defined but never used. (no-unused-vars)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:2:13: Missing space before function parentheses. (space-before-function-paren)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:3:1: Expected indentation of 2 spaces but found 4. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:4:1: Expected indentation of 0 spaces but found 2. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:5:1: Trailing spaces not allowed. (no-trailing-spaces)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:6:1: More than 1 blank line not allowed. (no-multiple-empty-lines)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:7:1: Expected indentation of 0 spaces but found 2. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:7:18: Missing space before function parentheses. (space-before-function-paren)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:8:1: Expected indentation of 2 spaces but found 4. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:9:1: Expected indentation of 0 spaces but found 2. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:10:1: Trailing spaces not allowed. (no-trailing-spaces)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:11:1: More than 1 blank line not allowed. (no-multiple-empty-lines)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:12:1: Expected indentation of 0 spaces but found 2. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:13:1: Expected indentation of 0 spaces but found 2. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:14:1: Trailing spaces not allowed. (no-trailing-spaces)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:15:1: Expected indentation of 0 spaces but found 2. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:16:1: Trailing spaces not allowed. (no-trailing-spaces)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:17:1: More than 1 blank line not allowed. (no-multiple-empty-lines)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:18:1: Expected indentation of 0 spaces but found 2. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:19:1: Expected indentation of 2 spaces but found 4. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:20:1: Expected indentation of 0 spaces but found 2. (indent)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:21:1: Trailing spaces not allowed. (no-trailing-spaces)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:21:1: Too many blank lines at the end of file. Max of 0 allowed. (no-multiple-empty-lines)
  /Users/lexikronowitz/Desktop/fse313/nodebb-f24-team-tbd-1/test/standardjs.js:21:3: Newline required at end of file but not found. (eol-last)
Screenshot 2024-10-23 at 3 16 50 PM

Added script to package.json

Screenshot 2024-10-24 at 11 12 04 PM

Standard Dependency
Screenshot 2024-10-24 at 11 12 58 PM

After calling npx standard --fix on the file to automatically fix the code (only manually removed the unused variable 'add' function:

function isEven (num) {
  return num % 2 === 0
}

const numbers = [1, 2, 3, 4, 5]
const evenNumbers = numbers.filter(isEven)

console.log('Even numbers:', evenNumbers)

for (let i = 0; i < numbers.length; i++) {
  console.log(`Number ${numbers[i]} is ${isEven(numbers[i]) ? 'even' : 'odd'}`)
}

Now calling npx standard we can see that it fixed all the errors expect the unused variable error:
Screenshot 2024-10-29 at 8 28 36 PM

@lexik04 lexik04 self-assigned this Oct 23, 2024
Copy link

@vsolskyyy vsolskyyy left a comment

Choose a reason for hiding this comment

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

Very detailed tests to ensure the tool works as expected. It exposes the errors in the code.

@KevnKey
Copy link

KevnKey commented Oct 24, 2024

The test looks to be working fine and the example code definitely shows the errors.

@lexik04 lexik04 added the enhancement New feature or request label Oct 25, 2024
Copy link

@ay0503 ay0503 left a comment

Choose a reason for hiding this comment

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

Might need to fix the linting issues for the deployment pipeline but otherwise lgtm!

@lexik04 lexik04 requested review from ay0503 and vsolskyyy October 30, 2024 00:58
@lexik04 lexik04 changed the title Standardjs installation and running Standardjs installation and running Oct 30, 2024
Copy link

@ay0503 ay0503 left a comment

Choose a reason for hiding this comment

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

really detailed love it.
nit: if we are going to merge though we want to get rid of the lining issues!

@KevnKey
Copy link

KevnKey commented Oct 30, 2024

This is great info showing how it runs and even fixes errors automatically, especially for everything except unused variable. It should be good to say it has been run at least once in the git flow cycle.

@ay0503 ay0503 self-requested a review October 31, 2024 22:18
Copy link

@ay0503 ay0503 left a comment

Choose a reason for hiding this comment

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

I just added the StandardJS workflow. It seems that because we have added the static tool to the codebase without changing the codebase to this StandardJS linting standards, the pipeline isn't passing. We can't push unless it passes, but at the same time I see more than 7000 lines of code that needs to be fixed. I tried the automatic formatted but it also seems we have some undefined/null prevention linting rules that we can't automatically fix. It also seems unfeasible for us to go through every line and fix them given the codebase is already so big.

@coveralls
Copy link

coveralls commented Oct 31, 2024

Pull Request Test Coverage Report for Build 11620981110

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 82.666%

Totals Coverage Status
Change from base Build 11620883537: 0.0%
Covered Lines: 22322
Relevant Lines: 25582

💛 - Coveralls

@ay0503
Copy link

ay0503 commented Oct 31, 2024

It looks like the standard linter was running on all files. I changed it to only work on the single file we created to get it to pass the pipelines.

@ay0503 ay0503 merged commit b7683c1 into f24 Oct 31, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants