Usage

Interactive use

Drag the ASLint tool link to your toolbar and use it as a regular bookmarklet.

CI/CD integration

Use a small code snippet:

(function() {
  var s = document.createElement('script');
  var timeout = null;

  function clearCloseTimeout() {
    if (typeof timeout === 'number') {
      clearTimeout(timeout);
      timeout = null;
    }
  }

  function showMessage(message) {
    hideMessage();

    var messageContainer = document.createElement('div');
    messageContainer.id = 'aslintInitMessage';
    messageContainer.style = 'position: fixed; top: 0; left: 0; right: 0; max-width: 750px; margin: 0.25em auto 0; padding: 0.25em 0.75em; border-radius: 3px; box-shadow: none; font-size: 1em; text-align: center; color: white; background: red; z-index: 999999;';
    messageContainer.textContent = message;

    var closeButton = document.createElement('button');
    closeButton.type = 'button';
    closeButton.style = 'margin-left: 0.5em;';
    closeButton.textContent = 'Close';
    closeButton.onclick = function() {
      hideMessage();
    };

    messageContainer.appendChild(closeButton);
    document.body.appendChild(messageContainer);
  }

  function hideMessage() {
    var el = document.getElementById('aslintInitMessage');

    if (el !== null) {
      el.parentNode.removeChild(el);
    }

    clearCloseTimeout();
  }

  function loadedCallback() {
  }

  function failedCallback(err) {
    showMessage('Failed to load ASLint. Potential reasons: Content Security Policy or ASLint file is not reachable.');

    timeout = setTimeout(function() {
      hideMessage();
    }, 5000);
  }

  function resultsCallback(results) {
    console.log(results);
  }

  s.type = 'text/javascript';
  s.async = true;
  s.src = (document.location.protocol === 'https:' ? 'https:' : 'http:') + '//18.217.221.135/api/aslint/loader/loader.js';

  window.aslint = {
    config: {
      asyncRunner: true,
      reportFormat: {
        JSON: true
      },
      resultsCallback: resultsCallback,
      visibleUI: true
    }
  };

  if (typeof s.addEventListener === 'function') {
    s.addEventListener('load', loadedCallback);
    s.addEventListener('error', failedCallback);
  }

  document.body.appendChild(s)
})();

Configuration options for ASLint

  • asyncRunner – set to true if rules must be evaluated asynchronously without blocking UI rendering. It is useful when you want to reevaluate rules quite frequently on the content, but you do not want to “freeze” UI.
  • context – CSS Selector or XPath. Limit scanning to the selected element and all its content.
  • reportFormat – type of results format. Currently only JSON is supported.
  • resultsCallback – a function callback that will be called once all testing will be finished.
  • visibleUItrue if UI of ASLint must be rendered, otherwise false (default). Useful when ASLint is used in a build pipeline or from developer console.