All files / packages/design-system/scripts/gulp/lint index.js

0% Statements 0/21
100% Branches 0/0
0% Functions 0/11
0% Lines 0/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137                                                                                                                                                                                                                                                                                 
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
 
import gulp from 'gulp';
import cache from 'gulp-cached';
import lintspaces from 'gulp-lintspaces';
import eslint from 'gulp-eslint-new';
import stylelint from 'gulp-stylelint-esm';
import htmlhint from 'gulp-htmlhint';
import yamlValidate from './validate-yaml.js';
import iconlint from '../plugins/lint-icons';
import tokenlint from '../plugins/lint-tokens';
 
import validateMarkup from './validate-markup';
 
export const sass = () =>
  gulp
    .src(['ui/**/*.scss'])
    .pipe(cache('stylelint'))
    .pipe(
      stylelint({
        reporters: [
          {
            formatter: 'string',
            console: true,
          },
        ],
        failAfterError: true,
      }),
    );
 
export const spaces = () =>
  gulp
    .src([
      '!(*.local).{js,json,md,yml,txt}',
      '.*',
      '!.DS_Store',
      '!LICENSE-icons-images.txt',
      '!CONTRIBUTING.md',
      'ui/**/*.*',
      'scripts/**/*.{js,sh,jsx}',
      '!**/__snapshots__/*',
    ])
    .pipe(cache('lintspaces'))
    .pipe(
      lintspaces({
        editorconfig: '.editorconfig',
        ignores: [
          /\/\*[\s\S]*?\*\//g, // Ignore comments
        ],
      }),
    )
    .pipe(lintspaces.reporter({ breakOnWarning: true }));
 
export const javascript = (files, options) =>
  gulp
    .src(['!(*.local).js', 'shared/**/*.{js,jsx}', 'ui/**/*.{js,jsx}', '!**/*.spec.{js,jsx}'])
    .pipe(cache('lintjs'))
    .pipe(eslint())
    .pipe(eslint.format('codeframe'))
    .pipe(eslint.failAfterError());
 
export const javascriptTest = () =>
  gulp
    .src(['__tests__/**/*.spec.{js,jsx}', '!**/*.spec.{js,jsx}'])
    .pipe(cache('lintjs'))
    .pipe(eslint())
    .pipe(eslint.format('codeframe'))
    .pipe(eslint.failAfterError());
 
export const html = () =>
  gulp
    .src('.html/*.html')
    .pipe(
      htmlhint({
        // Rules documentation:
        // https://github.com/yaniswang/HTMLHint/wiki/Rules
        'alt-require': true,
        'attr-lowercase': [
          'viewBox',
          'preserveAspectRatio',
          'filterUnits',
          'gradientTransform',
          'stdDeviation',
          'autoComplete',
          'srcDoc',
        ],
        'attr-no-duplication': true,
        'attr-unsafe-chars': true,
        'attr-value-double-quotes': true,
        'attr-value-not-empty': true,
        'doctype-html5': true,
        'id-class-ad-disabled': true,
        'id-unique': true,
        'inline-script-disabled': false,
        'src-not-empty': true,
        'tag-pair': true,
        'tag-self-close': true,
        'tagname-lowercase': false,
        'title-require': true,
        // TODO: enable when https://github.com/yaniswang/HTMLHint/issues/139 is fixed
        // as <div>&lt;div></div> raises errors at the moment
        'spec-char-escape': false,
      }),
    )
    .pipe(htmlhint.failReporter());
 
export const markup = (done) => validateMarkup().fork(console.error, () => done());
 
export const tokensYml = () =>
  gulp.src(['./ui/components/**/tokens/*.yml', './design-tokens/aliases/*.yml']).pipe(yamlValidate());
 
export const tokensComponents = () =>
  gulp
    .src([
      './ui/components/**/tokens/*.yml',
      '!./ui/components/**/tokens/bg-*.yml', // icons
      '!./ui/components/**/tokens/force-font-commons.yml', // fonts
    ])
    .pipe(tokenlint())
    .pipe(tokenlint.report('verbose'));
 
export const tokensAliases = () =>
  gulp
    .src(['./design-tokens/aliases/*.yml'])
    .pipe(tokenlint({ prefix: false }))
    .pipe(tokenlint.report('verbose'));
 
/**
 * To ensure that only the recommended colors are used for standard and action icons, a linter is being used to evaluate them
 */
export const iconsYml = () =>
  gulp
    .src(['./design-tokens/bg-standard.yml', './design-tokens/bg-actions.yml'])
    .pipe(iconlint())
    .pipe(iconlint.report());