Commit Graph

68 Commits

Author SHA1 Message Date
Ryan Shaw 637b8b756d [eslint] have --fix add copyright header for you
Test plan:
* Run eslint —fix against a file that doesn’t have a copyright header
  (Eg: eslint --fix app/coffeescripts/AssignmentDetailsDialog.js )
* it should add the copyright header for you
* run eslint on a file that already has a proper copyright header
* it should not duplicate it

Change-Id: I0bc05b6cc267fb74909f7a0fe0e93ecda1e2136e
Reviewed-on: https://gerrit.instructure.com/140757
Tested-by: Jenkins
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2018-02-15 20:01:41 +00:00
Jeremy Neander 929416a47c adjust eslint 'prefer-destructuring' rule
This rule was configured to allow for conditional assignment
without forcing destructuring which requires the use of wrapping
parentheses and a lonely semicolon. This style was roundly
rejected after discussion.

Example:

  let foo
  ;({foo} = bar)

Change-Id: I3cfe1be2ac18ce88481367830e2eb30effbc3340
Reviewed-on: https://gerrit.instructure.com/140916
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Tested-by: Jenkins
Product-Review: Jeremy Neander <jneander@instructure.com>
QA-Review: Jeremy Neander <jneander@instructure.com>
2018-02-14 17:02:23 +00:00
Steven Burnett 4bcdea0497 Revert "Enforce prettier formatting with eslint"
This reverts commit 7d9ef5c77e.

Change-Id: Ibb49916220b035205609d38a7e1c6dcfee9d04a6
Reviewed-on: https://gerrit.instructure.com/137551
Reviewed-by: Venk Natarajan <vnatarajan@instructure.com>
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Tested-by: Jenkins
Product-Review: Steven Burnett <sburnett@instructure.com>
QA-Review: Steven Burnett <sburnett@instructure.com>
2018-01-11 00:10:42 +00:00
Jeremy Neander 9e2645071a turn off array destructuring linter rule
Change-Id: I829458cde3b979030f305a71bc943246a388d042
Reviewed-on: https://gerrit.instructure.com/137475
Reviewed-by: Derek Bender <djbender@instructure.com>
Tested-by: Jenkins
Product-Review: Jeremy Neander <jneander@instructure.com>
QA-Review: Jeremy Neander <jneander@instructure.com>
2018-01-10 19:04:48 +00:00
Ryan Shaw 7d9ef5c77e Enforce prettier formatting with eslint
This makes prettier errors eslint warnings. So when you 
`eslint --fix some/file.js` it will format it with prettier

to try this out, apply this commit and run eslint against your files.
this change will make it so it runs it through prettier and forces
your code to look like prettier would output. But it doesn’t force
Prettier formatting to pass eslint since they are just warnings so if
you really want to format your code differently than prettier you can.

Change-Id: I4f1cdf4962173002a7dc22138be06cc66b842190
Reviewed-on: https://gerrit.instructure.com/131773
Tested-by: Jenkins
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2018-01-10 18:09:10 +00:00
Steven Burnett 8703baf26d remove eslint rule for no-typo
Test Plan:
-N/A

Change-Id: I255d1341c1c5a6b2d52a4da7cf3137f3d4db01f7
Reviewed-on: https://gerrit.instructure.com/136115
Reviewed-by: Ryan Shaw <ryan@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
Tested-by: Jenkins
2017-12-19 18:56:49 +00:00
Ryan Shaw 88c1c61bdf Add Jest for testing JavaScript
closes: CNVS-34337

* For now, you can only test things that don’t require any coffeescript
  files
* Write your tests using es6 module syntax
* see app/jsx/shared/helpers/__tests__/parseLinkHeader.test.js for an
  example

test plan:
* run `yarn run jest`
* you should see some output like:
 PASS  app/jsx/shared/helpers/__tests__/parseLinkHeader.test.js
 PASS  app/jsx/actAs/__tests__/ActAsModal.test.js

Test Suites: 2 passed, 2 total
Tests:       5 passed, 5 total
Snapshots:   1 passed, 1 total
Time:        3.072s
Ran all test suites.
* make sure it runs on jenkins build

Change-Id: Ia79cd8ce35dc863c4cc5ce7512998320c7cfdb84
Reviewed-on: https://gerrit.instructure.com/100685
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Tested-by: Jenkins
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2017-12-14 22:08:09 +00:00
Ryan Shaw ad2b78110a [eslint] relax ‘one-var’ to allow `let foo, bar`
…but still force `let foo=1, bar=2` to be:
let foo=1
let bar=2

I don’t actually find any value in enforcing this rule at all and think
we could ignore it altogether but rather than advocating we remove it 
completely, this commit just makes it so you can combine uninitialized
variable declarations at the top.

I frequently see this in spec files where we do something like

let subject, result, whatever
//and then in a ‘beforeEach()’ we assign values to those
//and then in each test(..) they are used

What say ye all?

Test plan:
* look at follow-on commit to this that changes MessageStudentsSpec.js
* it should not have eslint errors about:
  `error  Split 'let' declarations into multiple statements`

Change-Id: I7aafac3a395bac221e9e9b3111a82d0af4671ddb
Reviewed-on: https://gerrit.instructure.com/134822
Tested-by: Jenkins
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2017-12-07 16:50:32 +00:00
Ryan Shaw 2122e6b9bd eslint: relax no-return-assign to 'except-parens'
a common pattern to set a ref for a react element is:
<div ref={e => this.refName = e} />

But if you are using our eslint rules (currently set to 
"no-return-assign": ["error", "always”]) it will force you to do:
<div ref={e => {this.refName = e}} />

And now, if you are using prettier, it will format that as:
<div ref={e => {
  this.refName = e
}} />

That seems needlessly verbose. With this change you can now do:
<div ref={e => (this.refName = e)} />

And both eslint and prettier will be ok with that

Test plan:
* verify functions that return an assignment do what you want in eslint

Change-Id: I56abfdb21a7bf3f5b3eae8088f27749f41f2371c
Reviewed-on: https://gerrit.instructure.com/131788
Tested-by: Jenkins
Reviewed-by: Felix Milea-Ciobanu <fmileaciobanu@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2017-11-03 18:50:18 +00:00
Cameron Matheson 9fab292083 add prettier and config-eslint-prettier
Change-Id: I16b8e5337435136e6b8ea1e1f7edb05612d8a2aa
Reviewed-on: https://gerrit.instructure.com/123269
Reviewed-by: Ryan Shaw <ryan@instructure.com>
Tested-by: Jenkins
Product-Review: Cameron Matheson <cameron@instructure.com>
QA-Review: Cameron Matheson <cameron@instructure.com>
2017-08-24 16:41:57 +00:00
Ryan Shaw d556959f2f eslint proposal: ignore ‘padded-blocks’
all of our code that uses AMD looks something like:

define([
  ‘jquery’,
  ‘underscore’
], ($, _) => {

  $(doStuff)
  …

It doesn’t make it any “better” to force people to remove
that blank line at the top of the callback. In fact, leaving it puts
it on par with what we already lint for to *enforce* a blank
line between es6 import or commonjs require() statements and the rest
of your code.

Change-Id: I3dd2051200f6bf458732940306cd044bf631b463
Reviewed-on: https://gerrit.instructure.com/112177
Tested-by: Jenkins
Reviewed-by: brian kirkby <bkirkby@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2017-05-22 18:50:09 +00:00
Ryan Shaw 1e714d9256 Elsint proposal: ignore camelcase
…Because we have a ton of existing code that
Does things like `const $user_name = $('#user_name’)`
And it doesn’t make anything “better” to force people to
go around renaming all those. And, although with BEM / React
you probably wouldn’t write code like that in new stuff,
If the DOM ID really is #user_name, for greppability it arguably
is better to keep the js variable and the dom id the same.
(or at least it is not objectively worse than having one with 
underscores and one in camelCase).

Change-Id: I042deb3a2bd612eaf74addb141015d288a7330fe
Reviewed-on: https://gerrit.instructure.com/112176
Tested-by: Jenkins
Reviewed-by: brian kirkby <bkirkby@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2017-05-22 18:49:43 +00:00
Ryan Shaw ac0860c4df eslint public/js with same rules as app/jsx
Closes: CNVS-36236

We now treat code in public/javascripts
exactly the same as app/jsx. Since we pass
it all to babel we can lint with the same rules
as we do app/jsx and you can use all the modern
syntax/features/babel goodness there. There is literally
no excuse to write old crapy javascript anymore.

Now we can start adding some commits that eslint -fix all the existing
stuff in public javscripts.

Test plan:
* if you run eslint public/javascripts/instructure.js it should
  give you a bunch of warnings about converting things from var
  to let/const and other stuff like that. 

Change-Id: I5d400b958ae33f3f13f7f6a9c3505a4f7b5843db
Reviewed-on: https://gerrit.instructure.com/112146
Tested-by: Jenkins
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2017-05-19 18:29:09 +00:00
Ryan Shaw fd316a23ee [eslint] no-underscore-dangle and some import rules
Test Plan:
  - Breaking those rules will be okay or in the case of
    named stuff it fails :)

Change-Id: I5d41ec8d12aee5a59b6f35da0a86ed1571950998
Reviewed-on: https://gerrit.instructure.com/100877
Tested-by: Jenkins
Reviewed-by: Ryan Shaw <ryan@instructure.com>
Product-Review: Clay Diffrient <cdiffrient@instructure.com>
QA-Review: Clay Diffrient <cdiffrient@instructure.com>
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
2017-02-06 15:40:11 +00:00
Ryan Shaw 3e3024b06e [eslint] add eslint-plugin-promise
closes: CNVS-34124

These are it’s default rules:
    "rules": {
        "promise/always-return": "error",
        "promise/no-return-wrap": "error",
        "promise/param-names": "error",
        "promise/catch-or-return": "error",
        "promise/no-native": "off",
        "promise/no-nesting": "warn",
        "promise/no-promise-in-callback": "warn",
        "promise/no-callback-in-promise": "warn",
        "promise/avoid-new": "warn"
    }

the only one I changed was set avoid-new to ignore
because I have noticed that there was a few times
where I really did need/want to make my own promise.
I am open to debate on what others think though

Test Plan:
* the eslint errors on your code that uses promises
  should have the warnings you expect

Change-Id: I46e5f2d1d2ded2dba1e5aeb2ebcf303bcd4c5981
Reviewed-on: https://gerrit.instructure.com/98201
Tested-by: Jenkins
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2017-01-04 18:21:04 +00:00
Clay Diffrient 1a09008098 [eslint] Make ENV show as a global everywhere
Test Plan:
  - Using ENV should not show as a problem anywhere

Change-Id: I4b37a95606755e21716df0dfb61f26a85e295fe9
Reviewed-on: https://gerrit.instructure.com/98198
Reviewed-by: Jeremy Neander <jneander@instructure.com>
Tested-by: Jenkins
Reviewed-by: Ryan Shaw <ryan@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
2016-12-20 21:39:47 +00:00
Jon Willesen 4863693bf7 fix js linting with proper filename
Change-Id: Iae08df35c1ac92604cd8d0aa1914f7deddd6ab3b
Reviewed-on: https://gerrit.instructure.com/97961
Tested-by: Jenkins
Reviewed-by: Frederick Polgardy <fpolgardy@instructure.com>
Product-Review: Jon Willesen <jonw+gerrit@instructure.com>
QA-Review: Jon Willesen <jonw+gerrit@instructure.com>
2016-12-19 21:08:14 +00:00
Clay Diffrient 77501e2688 [eslint] Improve setup for different JS levels
This makes it so eslint handles situations where we don't have
ES2015+ available, while still allowing us to have our own common
rules.

Change-Id: I86b49a32433970afbcc48ef0f6fcdd7301795b63
Reviewed-on: https://gerrit.instructure.com/97872
Tested-by: Jenkins
Reviewed-by: Dan Minkevitch <dan@instructure.com>
Product-Review: Clay Diffrient <cdiffrient@instructure.com>
QA-Review: Clay Diffrient <cdiffrient@instructure.com>
2016-12-16 23:33:40 +00:00