Git Product home page Git Product logo

jadelint's People

Contributors

pyrosa avatar rrdelaney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gitter-badger

jadelint's Issues

Should OnlyHTMLDoctype should accept "html" and "HTML" doctypes?

I ran the [email protected] linter against my views/*.jade folder and it failed because I had my doctype set to "HTML" instead of "html" (see /src/rules/OnlyHTMLDoctype.coffee). Not sure if it should be case insensitive or not.

➜  idea-town git:(master) ✗ cat views/layout.jade
doctype HTML
html(lang="en")
  include includes/header

  body
    block content

    include includes/footer
    script(type="text/javascript" src="scripts/main.min.js")

➜  idea-town git:(master) ✗ jadelint views/*.jade

views/layout.jade
  ✖  line 1  Only HTML doctypes are allowed

✖  1 warning
➜  idea-town git:(master) ✗ cat views/layout.jade
doctype html
html(lang="en")
  include includes/header

  body
    block content

    include includes/footer
    script(type="text/javascript" src="scripts/main.min.js")

➜  idea-town git:(master) ✗ jadelint views/*.jade

✔ No problems found!

Rule: consistent use of single/double quotes

A simple one: should choose one type of quotes (single/double option?) and stick to it (document wide):

//- Invalid
a(href="/kill", title='me')

//- Invalid
a(href="/johhny.html")
    img(src='mnemonic.png')

//- Valid (with option "single"?)
a(href='/', title='root')
    img(src='beer.jpg')

//- Valid (with option "double"?)
a(href="/just", title="do")
    img(src="it.svg")

Rule: whitespace between tags

So, how to deal with whitespace? Sadly, p.two has best compiled version but is poorly readable in jade.

p.one this
    strong is
    | madness
buf.push("<p class=\"one\">this<strong>is</strong>madness</p>");
p.two this
    strong  is
    |  madness
buf.push("<p class=\"two\">this<strong> is</strong> madness</p>");
p.three this
    = " "
    strong is
    = " "
    | madness
buf.push("<p class=\"three\">this" + (jade.escape(null == (jade_interp = " ") ? "" : jade_interp)) + "<strong>is</strong>" + (jade.escape(null == (jade_interp = " ") ? "" : jade_interp)) + "madness</p>");
p.four this
    != " "
    strong is
    != " "
    | madness
buf.push("<p class=\"four\">this" + (null == (jade_interp = " ") ? "" : jade_interp) + "<strong>is</strong>" + (null == (jade_interp = " ") ? "" : jade_interp) + "madness</p>");

UseUTF8 rule should be case insensitive

Related to #4, it seems that the UseUTF8 rule isn't case sensitive:

➜  idea-town git:(master) ✗ jadelint views/**/*.jade

views/includes/header.jade
  ✖  line 2  Only use UTF-8 as charset

✖  1 warning
➜  idea-town git:(master) ✗ cat views/includes/header.jade
head
  meta(charset="utf-8")
  meta(name="description" content=desc)
  meta(name="keywords" content=keys)
  meta(name="viewport" content="width=device-width initial-scale=1")
  title= title

  link(rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,300")
  link(rel="stylesheet" href="styles/main.min.css")
``

Rule: unnecessary #{...}

Proposition for a new rule:

Avoid unnecessary use of #{...}
default: warning

//- Valid
p= someVariable

//- Invalid
p #{someVariable}
//- Valid
a(href=my.url)

//- Invalid
a(href="#{my.url}")

What do you think? Or is this just personal preference how to inject variables?

RequireStatementInCodeBock

Why it is invalid? Example code from http://jade-lang.com/reference/conditionals/

- var user = { description: 'foo bar baz' }
- var authorised = false
#user
    if user.description
        h2 Description
        p.description= user.description
    else if authorised
        h2 Description
        p.description.
            User has no description,
            why not add one...
    else
        h1 Description
        p.description User has no description
example.jade
  ✖  line 4   Require Statement in Code Block
  ✖  line 7   Require Statement in Code Block
  ✖  line 12  Require Statement in Code Block

✖  3 warnings

BTW, these are warnings or errors?

edit: nevermind, dot after p.description. is actually working

Improved file context messages needed

When running jadelint on a directory, it would be helpful to include more context in the the warnings and deprecation sections. Here's what I see:

Deprecated method of calling mixins, use +name syntax (undefined line 73)
Deprecated method of calling mixins, use +name syntax (undefined line 78)
Warning: missing space before text for line 118 of jade file "undefined"
Deprecated method of calling mixins, use +name syntax (undefined line 38)
Deprecated method of calling mixins, use +name syntax (undefined line 114)
Deprecated method of calling mixins, use +name syntax (undefined line 28)
Deprecated method of calling mixins, use +name syntax (undefined line 33)
Deprecated method of calling mixins, use +name syntax (undefined line 35)
Deprecated method of calling mixins, use +name syntax (undefined line 37)
Deprecated method of calling mixins, use +name syntax (undefined line 39)
Deprecated method of calling mixins, use +name syntax (undefined line 75)
Deprecated method of calling mixins, use +name syntax (undefined line 24)
Deprecated method of calling mixins, use +name syntax (undefined line 60)
Deprecated method of calling mixins, use +name syntax (undefined line 65)
Deprecated method of calling mixins, use +name syntax (undefined line 67)
Deprecated method of calling mixins, use +name syntax (undefined line 69)
Deprecated method of calling mixins, use +name syntax (undefined line 71)
Deprecated method of calling mixins, use +name syntax (undefined line 140)
Deprecated method of calling mixins, use +name syntax (undefined line 184)
Warning: missing space before text for line 101 of jade file "undefined"
Warning: missing space before text for line 157 of jade file "undefined"
Deprecated method of calling mixins, use +name syntax (undefined line 63)
Deprecated method of calling mixins, use +name syntax (undefined line 68)
Deprecated method of calling mixins, use +name syntax (undefined line 20)

I also don't understand the messages about jade file "undefined".

Add support for linting directories

I tried running [email protected] against my views/ directory and got the following error:

➜  idea-town git:(master) ✗ jadelint views

fs.js:488
  var r = binding.read(fd, buffer, offset, length, position);
                  ^
Error: EISDIR, illegal operation on a directory
    at Object.fs.readSync (fs.js:488:19)
    at Object.fs.readFileSync (fs.js:322:28)
    at module.exports.jadelint (/Users/pdehaan/.npm-packages/lib/node_modules/jadelint/target/jadelint.js:27:19)
    at Object.<anonymous> (/Users/pdehaan/.npm-packages/lib/node_modules/jadelint/bin/jadelint:3:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

Not sure if you need to add a couple more checks to src/jadelint.coffee to see if the filename is a file or directory before trying to call fs.readFileSync().

Workaround:

➜  idea-town git:(master) ✗ jadelint views/*.jade

views/layout.jade
  ✖  line 1  Only HTML doctypes are allowed

✖  1 warning

Question: Interested in pooling our efforts?

Hey, I've also been working on a Jade linter and style checker; https://github.com/benedfit/jadelint. My plan was to be non-opinionated and provide users with a means to set their own rules.

To cut to the chase, I'm disappointed that I've missed the boat and not snapped up jadelint on npm for my linter, so I was wondering if you were interested in pooling our efforts, and porting over some of the rules you have already created into more generic ones (e.g. DontUseBTags, DontUseSTags, etc, could be reengineered into disallowTags: [ 'b', 's' ]), in order to create a tool that the whole community can enjoy and use in a way that suites their individual needs?

Problem with html5 tags with attributes without values

Hello,

Looks like jadelint doesn't like tags with attributes without values, which are ok with jade and html5 specification.

Example jade file:

script(src="nope.js", async, defer)

Error:

/tmp/node_modules/jadelint/node_modules/text-table/index.js:59
return m ? m.index + 1 : c.length;

TypeError: Cannot read property 'length' of undefined
at dotindex (/tmp/node_modules/jadelint/node_modules/text-table/index.js:59:31)
at /tmp/node_modules/jadelint/node_modules/text-table/index.js:11:21
at Array.forEach (native)
at forEach (/tmp/node_modules/jadelint/node_modules/text-table/index.js:73:31)
at /tmp/node_modules/jadelint/node_modules/text-table/index.js:10:9
at Array.reduce (native)
at reduce (/tmp/node_modules/jadelint/node_modules/text-table/index.js:63:30)
at module.exports (/tmp/node_modules/jadelint/node_modules/text-table/index.js:9:20)
at Reporter.aggregate (/tmp/node_modules/jadelint/target/Reporter.js:23:16)
at module.exports.jadelint (/tmp/node_modules/jadelint/target/jadelint.js:44:16)

linter should walk from file path up to find .jadelintrc

per d9d/atom-linter-jade#3, the linter only looks in the current directory for the .jadelintrc file. It should start from the file directory (not cwd) and walk up.

This is also an issue from the command line if calling the linter on a file in a different directory, e.g.:

jadelint src/file.jade

Alternatively, can you fork the config file loading code so that I can easily do something like .setConfig(json|fileName) and not have to duplicate this block of code:

try {
  conf = JSON.parse(fs.readFileSync('.jadelintrc'));
  try {
    for (rule in conf) {
      level = conf[rule];
      rules.rules[rule].prototype.level = level;
    }
  } catch (_error) {}
} catch (_error) {}

Syntax Error from attribute="#{{expression}}"

Syntax Error reported by linter on an attribute containing "#{{expression}}".

We have an angular directive mp-file with an attribute file-description:

In this case we have an entry that (trimmed down), looks like this in Jade:
mp-file(file-description="Certificate #{{ certificate.number }}")

This correctly compiles to html:
<mp-file file-description="Certificate #{{ certificate.number }}"></mp-file>

But this still throws a 'Syntax Error' through the linter.

It seem to match the #{

Angular matches on {{ expression }}, so in this case we might have
certificate.number = 123
with the intention is to set the file-description to Certificate #123

Errors when trying to install globally from npm

I'm trying to install this module globally from npm and am getting this error:

➜  ~  npm i jadelint -g
npm ERR! Darwin 14.4.0
npm ERR! argv "node" "/Users/pdehaan/.npm-packages/lib/node_modules/npm-next/node_modules/npm/cli.js" "i" "jadelint" "-g"
npm ERR! node v0.10.35
npm ERR! npm  v2.12.0
npm ERR! path /Users/pdehaan/.npm-packages/lib/node_modules/jadelint/bin/jadelint.js
npm ERR! code ENOENT
npm ERR! errno 34

npm ERR! enoent ENOENT, chmod '/Users/pdehaan/.npm-packages/lib/node_modules/jadelint/bin/jadelint.js'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/pdehaan/npm-debug.log

Looking through your commits, I think this was fixed by 01cac18 but it may just need to be version bumped and pushed to npm.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.