99x / w3c-link-validator

Command line tool, identifying broken links, validate basic html standards and reporting
https://www.npmjs.com/package/w3c-link-validator
MIT License
18 stars 11 forks source link

Display line and column numbers #48

Closed padarom closed 6 years ago

padarom commented 7 years ago

This is a possible solution for #44.

The function lineAndColumn takes the cheerio object, as well as the html of the tag to output line and column numbers for. It uses an external variable to keep track of which tags it has looked for already, which is required to allow for multiple tags with the exact same html. It then splits the whole file by lines up to the point at which the tag occurs.

shalithasuranga commented 7 years ago

Hi.. @padarom Could you please share your "npm test" output here.

Thanks

padarom commented 7 years ago

I did not write any new tests to check for the new functionality as I'm not familiar with mocha. It doesn't seem to be breaking any existing tests though:


> w3c-link-validator@1.0.0 test /Users/christopher/Code/w3c-link-validator
> mocha test/index.js

  CLI app main
    ✓ Command line initialization should return true

▶ http://example.com/

BASE    /
    ✓ Command line initialization(with parameters) should return true

  Alerts
 WARNING  Test Message
    ✓ alertWarning should return undefined
  ERROR   Test Message
    ✓ alertError should return undefined
 SUGGEST  Test Message
    ✓ alertSuggestion should return undefined

  HTML Validator
    ✓ setGlobals should return undefined
❯ Checking HTML guidelines..

HTML SUMMARY
✔ no problem found

    ✓ Sample HTML validation Should return an object
❯ Checking HTML guidelines..

 WARNING  The doctype is required just above the <html> tag, at the very start of each document you write.
  ERROR   <head> tag should be appeared
  ERROR   <title> should be added inside <head>

HTML SUMMARY
✖ 3 problem(s) found

    ✓ Sample HTML(Violates RULE SET #1) validation Should return an object
❯ Checking HTML guidelines..

 WARNING  Make sure to offer alternative access. For images that means use of meaningful alternative text
[15:4] <img src="https://www.google.lk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">

 SUGGEST  Make sure to offer alternative access. For images that means use of meaningful alternative text
[16:4] <img src="https://www.google.lk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" alt="">

HTML SUMMARY
✖ 1 problem(s) found
ℹ 1 suggestion(s)

    ✓ Sample HTML(Violates RULE SET #2) validation Should return an object
❯ Checking HTML guidelines..

 WARNING  <applet> is entirely obsolete, and must not be used by authors. Use <embed> or <object> instead
[15:4] <applet></applet>

HTML SUMMARY
✖ 1 problem(s) found

    ✓ Sample HTML(Violates RULE SET #3) validation Should return an object
❯ Checking HTML guidelines..

 WARNING  charset attribute in <link>,<a> is entirely obsolete, and must not be used by authors Use an HTTP Content-Type header on the linked resource instead.
[15:4] <a charset="Big5" href="testHTML-rule1.html">Test</a>

HTML SUMMARY
✖ 1 problem(s) found

    ✓ Sample HTML(Violates RULE SET #4) validation Should return an object

  Links
    ✓ setGlobals should return undefined
    ✓ isLocal should return true for same host url
    ✓ isLocal should return false for different host url
Adding 2 link(s) to the queue...

    ✓ linkChecker should return an array

  Main file
    ✓ w3clink initialization should return undefined
    ✓ isLocal should return true for same host url
    ✓ isLocal should return false for different host url

▶ http://www.example.com/

BASE    /
STATUS  200 OK
ELAPSED 0.26 secs

OVERALL LINK SUMMARY
✔ Total links        : 2
✔ Dead links         : 0
✔ Dead link Ratio    : 0.00%

OVERALL HTML SUMMARY
✔ HTML Problems      : 0
ℹ HTML Suggestions   : 0
STATUS  200 OK
ELAPSED 0.27 secs

❯ Checking HTML guidelines..

 WARNING  The doctype is required just above the <html> tag, at the very start of each document you write.

HTML SUMMARY
✖ 1 problem(s) found

Adding 1 link(s) to the queue...

EXT  http://www.iana.org/domains/example

▶ http://www.iana.org/domains/example

BASE    example
STATUS  200 OK
ELAPSED 1.38 secs

OVERALL LINK SUMMARY
✔ Total links        : 3
✔ Dead links         : 0
✔ Dead link Ratio    : 0.00%

OVERALL HTML SUMMARY
✖ HTML Problems      : 1
ℹ HTML Suggestions   : 0
    ✓ Validation execution should be executed without crash and return undefined (9503ms)

OVERALL LINK SUMMARY
✔ Total links        : 3
✔ Dead links         : 0
✔ Dead link Ratio    : 0.00%

OVERALL HTML SUMMARY
✖ HTML Problems      : 1
ℹ HTML Suggestions   : 0
    ✓ displaySummary should return undefined

  20 passing (10s)
padarom commented 6 years ago

Any plans for merging or doing anything with this any time soon?