Add more rules
benedfit opened this issue · 4 comments
Definite:
- attributeSeparator: " " / "," / ", " / " ," / " , "
- spaceAfterCodeOperator: require/disallow (now 2 rules)
- idLiterals: require/disallow (now 2 disallow rules for ID literals and class literals)
- quoteMarks: single/double/first one found
- disallowDuplicateAttributes: true
- disallowBlockExpansion: true
- disallowTagInterpolation: true
- disallowHtmlText: true
- literalsBeforeAttributes: require/disallow (has been refactored into multiple rules for class>attr, id>attr & class>id)
- disallowStringInterpolation: true
- disallowStringConcatenation: true
- requireLineFeedAtFileEnd: true
- disallow[Class/Id]AtributeWithStaticValue: true
- maximumLineLength: int
- maximumNumberOfLines: int
- disallowImplicitDiv: true
- validateIndentation: number, "\t"
- validateLineBreaks:
"CR"
,"LF"
,"CRLF"
- lint/check style of JS using: jshint, jscs, eslint, etc
- requireLowerCaseTags: true
- requireLowerCaseAttributes: true
- validateSelfClosingTags: true
- disallowMultipleLineBreaks: true
- disallowSpecifcTags: array of tag names
- disallowSpecificAttributes: array of tag names and attrs that should not exist
- requireSpecificAttributes: array of tag names and attrs that must exist
- validateAttributeValue: array of tag names and attrs to validate, accept string or regex as validator
- require/disallow spaces inside attribute brackets e.g.:
(blah='blah')
- require/disallow spaces inside attribute value array brackets e.g.:
class=['a', 'b']
- require/disallow spaces inside attribute value object brackets e.g.:
class={active: true }
- disallowMultipleAttributeBlocks: true
- disallowEmptyMixinParenthasis: true
Suggestions:
quotation marksno whitespace between attribute pairsblock expansionid as literal/attributerequire space after buffered codeno duplicate attributes or attribute blocksallow html in jadeno divsclasses proceed attributestag interpolation ???prefer variable interpolationline feed at end of filedon't use class attribute when literal will doline length of attributesrequirevar
no unnecessary closing tagsremove redundant whitespacerequired attributes for certain tags (e.g. img must have alt)disallow certain tagsvalidate boolean attributesstyle attributes use JSON (formatting rules for these)class attributes Array and/or JSON (formatting rules for these)multi-line unbuffered code formatno unnecessary string interpolation (e.g. h1 #{thing} should be h1= thing)no unnecessary string concat (e.g. h1= thing + 'blah' should be h1 #{thing} blah)- comment type (when to use block comments over multiple single line, space after operator)
- prefer built-in jade conditions and iteration
- some how validate if versionPath is being used ???
- slim line ifs (no brackets)
- validate inheritance (does layout exist, do blocks exist) ???
- class naming convention (BEM etc, match stylint ???)
- attribute ordering ???
- &attributes (formatting rules for these)
- validate filters
- validate include paths
- validate mixins for unused/undefined variables
- check for deprecated way of calling mixins
- validate deprecated literals such as old doctype or previous way of writing conditional comments
- space before/after attribute brackets and equals
- disallow specific empty attribute
A couple of suggestions for useful rules
- disallow attribute interpolation (i.e.
input(value="Hi #{name}")
would be invalid butinput(value="Hi " + name)
would be valid). Attribute interpolation is something I am considering deprecating. - Only allow statements in
-
code. i.e. the following code would be invalid
//- invalid
- var n = 0;
- while (n < 10)
- n++
li= n
Pretty much all uses for doing this have builtins that can replace them, and it makes it very hard to provide useful line numbers in errors. If you force all lines starting with -
to be valid statements, the problem is easy. e.g.
//- valid
- var n = 0;
while (n < 10)
- n++
li= n
@ForbesLindesay thanks for your thoughts. It's interesting to here that attribute interpolation is considered for deprecation, as our internal style preference was leaning towards it, is this the plan for all string interpolation?
May I ask why are you thinking of deprecating interpolation? I love using it, just like string substitution the template strings in ES6/ES2015, so I'd hate to see it go :).
@kevin-smets pugjs/pug#2095 details the reasoning, and in Jade 2, attribute interpolation will be deprecated. I'm still leaving the tests for it in place for now, but have changed the Clock preset to disallow them by default