Giter Club home page Giter Club logo

hint's Introduction

webhint

Build Status Gitter FOSSA Status

Quick start user guide

webhint is a customizable linting tool that helps you improve your site's accessibility, speed, cross-browser compatibility, and more by checking your code for best practices and common errors.

It can be run from the command line (CLI), via a browser extension, and as a VS Code extension.

To use it from the CLI you will need to install Node.js (v14.x or later) on your machine, and you can use npx to test it.

Testing with npx

Run the following command:

npx hint https://example.com

This will analyze https://example.com using the default configuration.

Installing webhint locally

Install webhint as a devDependency of your project:

npm install hint --save-dev

And then add a script task to your package.json:

{
    ...
    "scripts": {
        "webhint": "hint"
    }
}

And run it via:

npm run webhint -- http://localhost:8080

Or if you are using yarn you can skip the step to create a task and run directly:

yarn hint http://localhost:8080

To know more about webhint, how to configure it, etc. see the online user guide, or the local version for the most recent content.

Contributing to webhint

This project follows a monorepo pattern. That means that the code for all the webhint flavors (CLI, browser and VS Code extension, hints, formatters, etc.) are in here and are published as separate npm packages.

To build the project from the source you will need to install a recent version of node and yarn. Once you've done this run the following from the root of your cloned version:

yarn
yarn build

This can take a bit so please be patient.

To learn more about the internals of webhint, the structure of the project, how to create new hints, parsers, formatters, etc, take a look at the online contributor guide (or the local version).

Contributing to the browser and VS Code extensions

To learn about how to build one of the extensions please check the CONTRIBUTING.md files for each of these packages:

Code of Conduct

All projects in the webhintio organization follow this CoC which adheres to the OpenJS Foundation Code of Conduct.

Other important links

License

The code is available under the Apache 2.0 license.

FOSSA Status

hint's People

Contributors

actions-user avatar alrra avatar antross avatar austinkelleher avatar captainbrosset avatar chrisguttandin avatar coliff avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar flynnolivia avatar gesa avatar greenkeeper[bot] avatar hxlnt avatar iamhopp avatar isabellachen avatar jaspreet57 avatar jm-trd-ms avatar johnemau avatar kshyju avatar maggers avatar molant avatar pratiyush2706 avatar qczhou avatar qzhou1607-zz avatar sarvaje avatar shivangg avatar ststimac avatar utsavized avatar vidorteg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hint's Issues

Add rule(s) to check the usage of the `Strict-Transport-Security` HTTP header

  • Check if the header Strict-Transport-Security is sent for resources served over HTTPS.
  • Check if the max-age value is small (less than 10886400 seconds should be an error, no configuration possible).

Also inform users about https://hstspreload.org/? However, make it clear that:

  • the preload list cannot easily be undone (domains can be removed, but it takes months for a change to reach users, basically until those users upgrade to a new version of the browser)
  • they should only do this if they are sure that they can support HTTPS for their entire site and all its subdomains in the long run.

See also:

Add rule to check the usage of `<meta>` charset

Add rule(s) for HTTP compression

gzip

  1. Check is something is served compressed using gzip:

    Make a request with the Accept-Encoding: "gzip" header, then verify if the response is served with the Content-Encoding: "gzip" header and the body of the response starts with 1f 8b.

  2. What should be compressed with gzip:

    File type Commonly used
    file extension(s)
    Commonly used
    media types(s)
    Atom .atom application/atom+xml
    App Cache Manifest .appcache text/cache-manifest
    BMP .bmp image/bmp
    CSS .css text/css
    Cursors Images .cur image/x-icon
    image/vnd.microsoft.icon
    Embedded OpenType font .eot application/vnd.ms-fontobject
    Favicon .ico image/x-icon
    image/vnd.microsoft.icon
    HTML .html
    .htm
    ...
    text/html
    application/xhtml+xml
    HTML Components .htc text/x-component
    JavaScript .js application/javascript
    text/javascript
    JSON .json
    ...
    application/json
    application/<something>+json
    OpenType font .otf font/opentype
    RDF .rdf application/rdf+xml
    RSS .rss application/rss+xml
    Source Maps .map application/json
    SVG .svg image/svg+xml
    TrueType font .ttc
    .ttf
    application/x-font-ttf
    TXT .txt text/plain
    vCard .vcard
    vcf
    text/vcard
    VTT .vtt text/vtt
    XML .xml
    ...
    application/xml
    text/xml
    application/<something>+xml
    Web App Manifest .webmanifest
    .json
    application/manifest+json

    Notes:

    • Under 1K things should not necessarily be compressed.
    • WOFF fonts should not be compressed (see: h5bp/server-configs-apache#42).
    • SVGZ should be served with the Accept-Encoding: "gzip" header as they are compressed by default.

Zopfli

  1. Check is something is served compressed using Zopfli:

    Same as with gzip, just that we need to detect Zopfli.

  2. What should be compressed with Zopfli:

    Same as with gzip.

    Note(s):

    • We will need to a check if WOFF fonts use Zopfli compression internally.

Brotli

  1. Check is something is served compressed using Brotli.

    Make a request with the Accept-Encoding: "br" header, then verify if the response is served with the Content-Encoding: "br" header (no magic numbers?).

    Note: Brotli compressed responses should be served only over HTTPS.

  2. What should be compressed with Brotli:

    Same as with gzip.


Note: This is just a starting point, we will probably split this into more specific issues / rules.

Add rule to check for usage of NPAPI-based plugins

Add rule to check the usage of `<meta>` viewport

  • Check for if the tag is included, and has width=device-width.

    Note: For iOS 9+ initial-scale=1 is no longer needed (1, 2)

  • Check for values that create bad user experience such as user-scalable=no.

  • Check for values that are ignored such as user-scalable, min-scale, and max-scale.

    From https://webkit.org/blog/7367/new-interaction-behaviors-in-ios-10/:

    "Now, we ignore the user-scalable, min-scale and max-scale settings. If you have content that disabled zoom, please test it on iOS 10, and understand that many users will be zooming now."


See also:

Refactor rule-runner

We use rule-runner to test our rules. Right now, the biggest problem is that we need to create a bit of infrastructure around it to test the rules (some mocks, rely on jsdom, etc.).
We should refactor rule-runner in such a way that:

  • It tests all the available collectors (although this should be configurable because of the limitations with travis)
  • It's even easier to write rules

We should probably have a special web server we can control via the configuration in the rules. Port should be random so we can spin up several at the same time (tests are run in parallel).
It should accept text as HTML to return as well as a folder for static resources plus a way to configure some of the response headers.

Improvements to `types.ts`

We should do several things:

  • Split into multiple related files.
  • Rename it to interfaces.ts. All are interfaces IIRC.
  • Keep interfaces.ts as a way to aggregate all and export them if it makes sense.
  • Remove as many any as possible, probably by adding more interfaces. Tracked via #76

Make rules specify if they work with local files (`file://...`)

Not all rules (especially ones that do network related checks) make sense with local files, so currently those types of rules will need to have extra checks to work properly.

Wouldn't it be better if rules would specify (e.g.: have a property in meta) if they work or not with local files?

fetch::end should have the original url as second parameter on emit

Right now it is undefined or null (emitAsync('fetch::end', null, networkData);). I think the reason is we want to put in there the element that triggered the requests but I don't think that's the way to go.
We are analyzing that resource and we need a way to identify exactly so we can group errors related to it. Also, some events will not have a source tag.
The initiator should come in the networkData object and be optional.

Try running #84 with npm run site -- http://edge.ms and you will see issues are not well grouped and makes more sense to have the url directly there instead of looking for it under request or response.

Upgrade to sinon 2.1.0

Sinon has released a new major version since we started the tests on this project. We need to update as soon as possible so we don't get left behind now that we don't use it that much.

Add rule to check the usage of `apple-touch-icon`s

Migration to TypeScript and TypeDoc

Although the project started as plain JavaScript, we are going to migrate to TypeScript to help with the documentation and development process (intellisense, type checking, etc.).
This issue covers (if needed):

  • refactoring
  • documenting API
  • set up TypeDoc in build process
  • bug fixing

Testing

Epic to track all the places where we need to add tests (everywhere). Goal should be to have +90% code coverage.

All collectors should automatically download the same type of resources (scripts, styles, fonts, icons, etc.)

By default, the collectors will not request certain resources (e.g.: manifest file, all font files, etc.).

Since quite a few rules will need to analyze those requests/resources, it wouldn't make sense to have every rule add custom code to request them, so we should add a helper to do that and notify the subscribed rules.


What we might want to request (incomplete list):

  • manifest file (<link rel="manifest" href="site.webmanifest">)
  • rss and atom files (<link rel="alternate" ... href="...">)
  • font files (specified in @font-face rules)
  • images specified in css files, manifest file, etc.
  • video, audio, and subtitle files
  • source map files (e.g.: //# sourceMappingURL=example.js.map)

Deal with encoding differences in collectors

Discussion moved from #87 (comment):

Continuing the discussion about the encoding there are a couple things we can do. HTML5 defaults to utf8 but previous versions were ISO-8859-1 which are not supported by node directly. jsdom uses iconv-lite to do text transformations. I don't know how popular that encoding (or any other) are in non-western cultures.
We could:

  1. Accept the PR as it is with a known issues section in the documentation linking to an issue to fix it.
  2. Use iconv-lite to add support for the same encodings and maybe look into contributing back for the most popular missing ones. We will need to see what happens with jsdom collector because we are using request to get the initial HTML and by default uses utf8 and only supports the same that node does.

I'm not sure what percentage of the web is in non utf8 but we should check it and add support if it is significant if we want sonar to be successful.

Add rule(s) to check the usage of the `X-Frame-Options` HTTP header

  • Check if the header is sent for non-HTML resources (e.g.: on images, fonts, etc.) - done in c55bdfb.
  • Check if the header is sent with the value "DENY" on pages that allow a user to make a state changing operation (e.g: login pages, pages that contain one-click purchase links, checkout or bank-transfer confirmation pages, pages that make permanent configuration changes, etc.)
  • Other?

See also:

Add support for group rules

@molant:

Yes, we want to group them and I think it should be via the meta object. We can use the meta.docs.category or any another property we want. I don’t think extends is a good idea because that should be to extend a configuration set. We could add an option in .sonarrc to enable all rules within a category (that also works with the command line).

It could be something like:

“categories”: [“webapp”, “security”]

That can be mixed with the rules (rules will have higher priority so if we enable a category but disable a rule, all the rules for that category but that one will be enabled).

Problems for this approach:

  • How to set up the severity error (could be an object instead of just an array of strings)
  • How to set up the extended configuration (maybe it just enables the default values and then user needs to configure further via rules)

Find a way to (efficiently) detect if a resource was compressed using Zopfli

Since the Zopfli output (for the gzip option) is valid gzip content, there doesn't seem to be a straightforward and foolproof way to identify files compressed with Zopfli.

From an email discussion with @lvandeve:

There is no way to tell for sure. Adding information to the output to indicate zopfli, would actually add bits to the output so such thing is not done :) Any compressor can set the FLG, MTIME, and so on to anything it wants, and users of zopfli can also change the MTIME bytes that zopfli had output to an actual time.

One heuristic to tell that it was compressed with zopfli or another dense deflate compressor is to compress it with regular gzip -9 (which is fast), and compare that the size of the file to test is for example more than 3% smaller.


Other notes:

gzip

A gzip member header has the following structure

  +---+---+---+---+---+---+---+---+---+---+
  |ID1|ID2|CM |FLG|     MTIME     |XFL|OS | (more-->)
  +---+---+---+---+---+---+---+---+---+---+

where:

  • ID1 = 1f and ID2 = 8b - these are the magic numbers that uniquely identify the content as being gzip.

  • CM = 8 - this is a value customarily used by gzip

  • FLG and MTIME are usually non-zero values.

  • XFL will be either 0, 2, or 4:

    • 0 - default, compressor used intermediate levels of compression (when any of the -2 ... -8 options are used).
    • 2 - the compressor used maximum compression, slowest algorithm (when the -9 or --best option is used).
    • 4 - the compressor used fastest algorithm (when the -1 or --fast option is used).

Zopfli

On thing that Zopfli does is that it sets FLG and MTIME to zero, XFL to 2, and OS to 3, so basically files compressed with Zopfli will most likely start with 1f8b 0800 0000 0000 0203, unless things are changed by the user (which in general doesn't seem very likely to happen).

Now, regular gzip output might also start with that, even thought the chance of doing so is smaller:

  • Most web servers (e.g.: Apache, NGINX), by default, will not opt users into the best compression level, therefore, the output shouldn't have XFL set to 2.
  • Most utilities that output regular gzip will have non-zero values for MTIME and FLG.

So, if a file doesn't start with 1f8b 0800 0000 0000 0203, it's a good (not perfect) indication that Zopfli wasn't used, but it's a fast check compared to compressing files and comparing file sizes. However, if a file does start with that, it can be either Zopfli or gzip, and we cannot really make assumptions here.

Add rule to check for HTTP headers that provide information about the technology stack

Servers, frameworks, and server-side languages (e.g.: ASP.NET, PHP), often set, by default, HTTP headers with values that contains information about them: their name, version number, etc.

Sending those types of HTTP headers does not provide any value to users, contributes to header bloat, and just gives more information to any potential attackers about the technology stack being used.


List of headers:

  • Server
  • X-AspNet-Version
  • X-AspNetMvc-version
  • X-Powered-By
  • X-Runtime
  • X-Version

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.