Skip to content

Commit

Permalink
feat: warnings in eslint
Browse files Browse the repository at this point in the history
Allow d2-style to print warnings from ESLint.

Set a zero tolerance on warnings by making ESLint exit with a non-zero
code if there are any warnings.

A developer is required to either:

a)  fix the warning
b)  explicitly mark the code that triggered the warning with an
eslint-disable comment.

A good disable directive uses the comment syntax for ESLint:

    /* eslint-disable [rule] -- [comment] */

E.g.

    /* eslint-disable-next-line no-console -- we need to log here */
  • Loading branch information
varl committed Mar 10, 2021
1 parent 254342f commit 76e3e29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
15 changes: 8 additions & 7 deletions config/js/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const SEVERITY = 2

module.exports = {
extends: [
'eslint:recommended',
Expand All @@ -8,6 +6,9 @@ module.exports = {
'plugin:import/warnings',
],

// unignore implicit rules about what types of files can be linted
ignorePatterns: ['!.*'],

plugins: ['prettier'],

env: {
Expand All @@ -28,22 +29,22 @@ module.exports = {

rules: {
'max-params': [
SEVERITY,
'error',
{
max: 3,
},
],
'prefer-const': [
SEVERITY,
'error',
{
destructuring: 'any',
ignoreReadBeforeAssign: false,
},
],
'no-mixed-spaces-and-tabs': [SEVERITY],
'prettier/prettier': [SEVERITY],
'no-mixed-spaces-and-tabs': ['error'],
'prettier/prettier': ['error'],
'import/order': [
SEVERITY,
'error',
{
'newlines-between': 'never',
alphabetize: {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/eslint.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { resolveIgnoreFile } = require('../utils/files.js')
const { PACKAGE_ROOT } = require('../utils/paths.js')
const { PACKAGE_ROOT, ESLINT_CONFIG } = require('../utils/paths.js')
const { bin } = require('../utils/run.js')

exports.eslint = ({ files = [], apply = false, config }) => {
exports.eslint = ({ files = [], apply = false, config = ESLINT_CONFIG }) => {
const ignoreFile = resolveIgnoreFile(['.eslintignore'])
const cmd = 'eslint'
const args = [
'--no-color',
'--report-unused-disable-directives',
'--ignore',
'--quiet',
'--format=unix',
'--max-warnings=0',
`--resolve-plugins-relative-to=${PACKAGE_ROOT}`,
...(ignoreFile ? ['--ignore-path', ignoreFile] : []),
...(config ? ['--config', config] : []),
Expand Down
7 changes: 6 additions & 1 deletion src/tools/prettier.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const log = require('@dhis2/cli-helpers-engine').reporter
const { resolveIgnoreFile } = require('../utils/files.js')
const { PRETTIER_CONFIG } = require('../utils/paths.js')
const { bin } = require('../utils/run.js')

exports.prettier = ({ files = [], apply = false, config }) => {
exports.prettier = ({
files = [],
apply = false,
config = PRETTIER_CONFIG,
}) => {
const ignoreFile = resolveIgnoreFile(['.prettierignore'])
const cmd = 'prettier'
const args = [
Expand Down

0 comments on commit 76e3e29

Please sign in to comment.