Skip to content

Commit

Permalink
Merge pull request #44 from the-t-in-rtf/GH-43
Browse files Browse the repository at this point in the history
GH-43: Add tests for custom lint check configuration options. (resolves #43)
  • Loading branch information
amb26 authored Sep 6, 2021
2 parents 09b4d74 + e7edfc5 commit 2ffe21a
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 11 deletions.
81 changes: 81 additions & 0 deletions .fluidlintallrc-custom-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"sources": {
"json5": ["./src/**/*.json5", "./tests/**/*.json5", "./*.json5", "./tests/**/*.with.extensions"]
},
"eslint": {
"js": {
"excludes": "@expand:fluid.generate(64,'')",
"options": {
"overrideConfig": {
"rules": {
"indent": 0,
"no-console": 0,
"no-undef": 0,
"semi": 0,
"strict": 0
}
}
}
},
"json": {
"excludes": "@expand:fluid.generate(64,'')",
"options": {
"overrideConfig": {
"rules": {
"comma-dangle": 0,
"no-undef": 0
}
}
}
},
"md": {
"excludes": "@expand:fluid.generate(64,'')",
"options": {
"overrideConfig": {
"rules": {
"semi": 0
}
}
}
}
},
"json5lint": {
"excludes": ["tests/fixtures/json5/bad.json5"]
},
"jsonlint": {
"excludes": ["tests/fixtures/json/bad.json"]
},
"lintspaces": {
"jsonindentation": {
"excludes": "@expand:fluid.generate(64,'')",
"options": {
"indentation": false
}
},
"newlines": {
"excludes": "@expand:fluid.generate(64,'')",
"options": {
"newline": false
}
}
},
"markdownlint": {
"excludes": "@expand:fluid.generate(64,'')",
"options": {
"config": {
"single-trailing-newline": false,
"first-line-heading": false,
"single-trailing-newline": false
}
}
},
"mdjsonlint": {
"excludes": ["tests/fixtures/md/bad.md", "tests/fixtures/md/badJson5.md"]
},
"stylelint": {
"excludes": "@expand:fluid.generate(64,'')",
"options": {
"configFile": "@expand:fluid.module.resolvePath(%fluid-lint-all/.stylelintrc-custom.json)"
}
}
}
1 change: 1 addition & 0 deletions .fluidlintallrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"tests/fixtures/css/bad.css",
"tests/fixtures/scss/bad.scss",
"tests/fixtures/md/bad*.md",
"tests/fixtures/other/.bad",
"tests/fixtures/images/*",
"*.aiff",
"*.eot",
Expand Down
15 changes: 15 additions & 0 deletions .stylelintrc-custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "stylelint-config-fluid",
"rules": {
"block-closing-brace-newline-before": null,
"block-opening-brace-space-before": null,
"declaration-block-trailing-semicolon": null,
"declaration-colon-space-before": null,
"indentation": null,
"no-missing-end-of-source-newline": null,
"selector-max-empty-lines": null,
"selector-type-no-unknown": null,
"selector-pseudo-class-no-unknown": null,
"selector-descendant-combinator-no-non-space": null
}
}
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ particular library:
}
```

Here's an example that demonstrates how to change the excludes for a given check. The `lintspaces.newlines` check would
otherwise report any files that lack a trailing space as an error.
Here's an example that demonstrates how to change the excluded files for a given check. The `lintspaces.newlines`
check would otherwise report any files that lack a trailing space as an error.

```json
{
Expand All @@ -140,6 +140,29 @@ otherwise report any files that lack a trailing space as an error.
}
```

You can see clear examples of custom options for linting checks that support them in [this text fixture](.fluidlintallrc-custom-options.json).
Here's the stylelint configuration from that fixture:

```json
{
"stylelint": {
"options": {
"configFile": ".stylelintrc-custom.json"
}
}
}
```

Stylelint also supports a `config` option where you can pass in the same rules you would write in a configuration file,
but setting `config` will prevent any of the options in your `configFile` from being used. Best practice is to extend
another configuration file and overlay your own exceptions, as demonstrated in [this text fixture](.stylelintrc-custom.json).

Each check is free to interpret relative paths in its own way. In the above example, stylelint would look for the file
relative to the repository in which the checks are run. The default stylelint options provided by this package make use
of [`fluid.module.resolvePath`](https://docs.fluidproject.org/infusion/development/nodeapi#fluidmoduleresolvepathpath)
to ensure that [the default configuration file](.stylelintrc.json) is used regardless of where your package manager
chooses to install fluid-lint-all.

## Adding (or Disabling) Default Includes and Excludes

There are global includes and excludes defined by default. See [this file](./src/js/lint-all.js) for the default
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fluid-lint-all",
"version": "1.1.4",
"version": "1.1.5",
"description": "Run the Fluid community's standard linting checks.",
"main": "index.js",
"bin": {
Expand All @@ -22,24 +22,24 @@
},
"homepage": "https://github.com/fluid-project/fluid-lint-all",
"dependencies": {
"@textlint/markdown-to-ast": "6.2.6",
"eslint": "7.17.0",
"@textlint/markdown-to-ast": "12.0.2",
"eslint": "7.32.0",
"eslint-config-fluid": "2.0.0",
"eslint-plugin-jsdoc": "30.7.13",
"eslint-plugin-jsdoc": "36.0.7",
"eslint-plugin-markdown": "1.0.2",
"fluid-glob": "1.0.4",
"infusion": "3.0.0-dev.20210312T233557Z.0b016a6dc.FLUID-6580",
"json5": "2.1.3",
"json5": "2.2.0",
"jsonlint": "1.6.3",
"lintspaces": "0.8.1",
"markdownlint": "0.22.0",
"markdownlint-config-fluid": "0.1.3",
"lintspaces": "0.9.0",
"markdownlint": "0.23.1",
"markdownlint-config-fluid": "0.1.4",
"minimatch": "3.0.4",
"minimist": "1.2.5",
"stylelint": "13.13.1",
"stylelint-config-fluid": "0.2.1"
},
"devDependencies": {
"node-jqunit": "1.1.8"
"node-jqunit": "1.1.9"
}
}
4 changes: 4 additions & 0 deletions tests/js/launcher-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ fluid.defaults("fluid.tests.lintAll.launcher.runner", {
shouldBeInvalid: true,
expectedMessage: "FAIL - One or more linting checks have errors."
},
customOptions: {
message: "We should be able to configure linting checks using custom options.",
configFile: ".fluidlintallrc-custom-options.json"
},
disabled: {
message: "We should be able to disable all checks using a configuration file.",
configFile: ".fluidlintallrc-disabled.json",
Expand Down

0 comments on commit 2ffe21a

Please sign in to comment.