- Javascript is dynamically typed, meaning that it guesses the type for each variable during assignment - you don't have to declare the type as in Java, which is statically typed.
- Types: boolean, string, number (integer and float), null, undefined, object (includes arrays)
- To check type: use "typeof" — e.g., typeof(2.5) — result: "number"
- Strings, Numbers, Arrays
- Strings (immutable) - charAt, split, concat
- e.g., a = "hello"; a.charAt(2); — result: "l"
- Arrays (mutable) - Pop, Push, Shift, Unshift
- ar = [1,2,3,4,5];
- To copy array to another variable w/o just creating another pointer to the same array in memory:
- Doesn't work:
- ar2 = ar; // just creates another pointer (ar2) to the same array in memory
- Works:
- ar2 = ar.slice(0) or ar2 = [... ar] // makes a copy of the array in memory and assigns it to ar2
- [The three dots (...) is the spread operator - available as of ES6]
- https://stackoverflow.com/a/23536726
- Array methods that use "callbacks" - map, filter, reduce
- e.g., ar.filter( (x) => (x === 'l') ) filters out all 'l' elements from the array.
- Q: Why parentheses and not curly brackets around x === 'l'?
- A: (<-->) Parentheses enclose only what you want returned (vs curly brackets).
- Further reading:
- Try it for free: https://www.codacy.com
- Our languages: Javascript, SQL, Python, PHP, Java
- Groups currently work in silos, w/ different coding styles and expertise levels – attempting to standardize.
- Demo: Live codacy repo.
- Project Dashboard - grade (A thru F scale),
- Plots -- % code affected vs date -- for issues listed and enumerated, complex files, duplicated code, coverage
- Logs - examples:
- Bob ignored patterns "enforce camel case"
- Bob ignored pattern "eslint_babel_array_bracket-spacing"
- "Hotspots" - areas of high activity
- Issues Panel: security, error prone, code style, compatibility, performance, unused code
- Issues are reported before the code is merged
- Can click into each and examine the issue, along with a descriptuion fothe issue in depth. Can create an issue on Github or setup a ticket through JIRA or ignore issue - Only available to administrators.
- Can filter by: Languages, Categories, Levels, Patterns, Authors
- Pull Request Tab - Opened Pull Request, Merged Pull Request
- Can block merges in github if not up to certain standards
- Developer will get a linked comment right on Github when issues are found - developer can click through to the issue on codacy to get a detailed description and feedback on their edit.
- Security Tab - OWASP Top 10 standards - Auth, CSRF, Cookies, Cryptography, DoS, File Access, Firefox OS, HTTP, Input Validation, Insecure Sotrage, Insecure modules/libraries
- Can click into each and check off further standards to enforce
- Green - enforcing; Yellow - not enforcing
- Code Patterns Tab - Rules configuration: Check off linters > For each linter, can check off patterns. As an admin, can pick for whole organization; can also set up patterns at the project level.
- Settings Tab
- Codacy Badge - HTML embed code A-to-F grade
- Slack integration
- Quality Settings - conditions that cause your commits and pull requests to succeed or fail. Can block pull requests as needed. Can block pull requests if...
- New issues are over x units
- Complexity is over x values
- Duplication is over x cloned blocks
- Coverage variation is under x percent
- Team Dashboard
- Grade, Issues, Complex Files, Duplication, Coverage; Open Pull Requests, Hotspots, etc.
- Developer Dashboard - grade and activity can inform individual performance assessments, esp. one's strengths
- Can we implement custom patterns? Currently unavailable and not yet a priority for the developers.
- Main takeaways: Codacy can...
- detect and alert coders to issues before merge.
- improve readability and thus promote collaboration
- serve as a learning tool to reinforce best practices.
- License - on a per user basis. User is defined as an account that logs in.
- Next step: set up a project for a trial run