linter-bundle 3.7.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,16 +6,40 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- [Show all code changes](https://github.com/jens-duttke/linter-bundle/compare/v3.7.0...HEAD)
9
+ [Show all code changes](https://github.com/jens-duttke/linter-bundle/compare/v3.8.0...HEAD)
10
+
11
+ ## [3.8.0] - 2023-08-28
12
+
13
+ ### Changed
14
+
15
+ - [eslint] Updated `@typescript-eslint` from `6.3.0` to `6.4.1`
16
+ - [eslint] Updated `eslint` from `8.47.0` to `8.48.0`
17
+ - [eslint] Updated `eslint-import-resolver-webpack` from `0.13.4` to `0.13.7`
18
+ - [eslint] Updated `eslint-plugin-import` from `2.28.0` to `2.28.1`
19
+ - [eslint] Updated `eslint-plugin-jsdoc` from `46.4.6` to `46.5.0`
20
+ - [eslint] Updated `eslint-plugin-n` from `16.0.1` to `16.0.2`
21
+ - [eslint] Updated `eslint-plugin-react` from `7.33.1` to `7.33.2`
22
+ - [stylelint] Updated `postcss-scss` from `4.0.6` to `4.0.7`
23
+ - [stylelint] Updated `stylelint` from `15.10.2` to `15.10.3`
24
+
25
+ ### Added
26
+
27
+ - [eslint] New rule [`restricted-filenames`](./eslint/rules/restricted-filenames.md), which restrict file and path names with given glob patterns.
28
+
29
+ [Show all code changes](https://github.com/jens-duttke/linter-bundle/compare/v3.7.0...v3.8.0)
10
30
 
11
31
  ## [3.7.0] - 2023-08-11
12
32
 
33
+ ### Changed
34
+
13
35
  - [eslint] Adjusted `jsdoc/tag-lines` configuration to enforce no empty like for `@typedef`, `@property` and `@returns`; and weakened line configuration for `@see`
14
36
 
15
37
  [Show all code changes](https://github.com/jens-duttke/linter-bundle/compare/v3.6.0...v3.7.0)
16
38
 
17
39
  ## [3.6.0] - 2023-08-11
18
40
 
41
+ ### Changed
42
+
19
43
  - [general] Change peer-dependency of `typescript` from `^4.0.0` to `>=4.0.0`
20
44
  - [eslint] Updated `@typescript-eslint` from `6.2.0` to `6.3.0`
21
45
  - [eslint] Updated `eslint` from `8.45.0` to `8.47.0`
@@ -25,9 +49,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
25
49
  - [eslint] Updated `eslint-plugin-jsdoc` from `46.4.5` to `46.4.6`
26
50
  - [eslint] Updated `eslint-plugin-react` from `7.33.0` to `7.33.1`
27
51
  - [stylelint] Updated `stylelint-scss` from `5.0.1` to `5.1.0`
28
- - [eslint] Removed deprecated (and currently disabled) `no-return-await` rule
29
52
  - [styleint] Added but disabled [`scss/function-disallowed-list`](https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/function-disallowed-list) rule
30
53
 
54
+ ### Removed
55
+
56
+ - [eslint] Removed deprecated (and currently disabled) `no-return-await` rule
57
+
31
58
  [Show all code changes](https://github.com/jens-duttke/linter-bundle/compare/v3.5.0...v3.6.0)
32
59
 
33
60
  ## [3.5.0] - 2023-07-28
package/README.md CHANGED
@@ -39,6 +39,7 @@ Beside that, the following additional rules are part of this bundle:
39
39
 
40
40
  - [no-global-undefined-check](./eslint/rules/no-global-undefined-check.md)
41
41
  - [no-unnecessary-typeof](./eslint/rules/no-unnecessary-typeof.md)
42
+ - [restricted-filenames](./eslint/rules/restricted-filenames.md)
42
43
 
43
44
  ### stylelint
44
45
 
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @file ESLint rule which ensures that only files which match given glob patterns are part of your project.
3
+ */
4
+
5
+ const path = require('path');
6
+
7
+ const micromatch = require('micromatch');
8
+
9
+ /**
10
+ * @type {import('eslint').Rule.RuleModule}
11
+ */
12
+ module.exports = {
13
+ meta: {
14
+ docs: {
15
+ description: 'Restrict file and path names with given glob patterns.',
16
+ recommended: true
17
+ },
18
+ messages: {
19
+ text: 'Disallowed filename "{{name}}".'
20
+ },
21
+ schema: {
22
+ type: 'array',
23
+ additionalItems: false,
24
+ items: [
25
+ {
26
+ type: 'object',
27
+ additionalProperties: false,
28
+ properties: {
29
+ basePath: {
30
+ type: 'string'
31
+ },
32
+ allowed: {
33
+ type: 'array',
34
+ items: {
35
+ type: 'string'
36
+ }
37
+ },
38
+ disallowed: {
39
+ type: 'array',
40
+ items: {
41
+ type: 'string'
42
+ }
43
+ }
44
+ }
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ create: (context) => ({
50
+ Program: (node) => {
51
+ const filePath = context.getFilename();
52
+ /** @type {{ basePath: string, allowed?: string[]; disallowed?: string[]; }[]} */
53
+ const options = context.options;
54
+
55
+ for (const { basePath, allowed, disallowed } of options) {
56
+ const normalizedName = path.relative(path.join(process.cwd(), basePath), filePath);
57
+
58
+ if (allowed && !disallowed) {
59
+ if (!micromatch.isMatch(normalizedName, allowed, { dot: true })) {
60
+ report();
61
+ return;
62
+ }
63
+ }
64
+ else if (!allowed && disallowed) {
65
+ if (micromatch.isMatch(normalizedName, disallowed, { dot: true })) {
66
+ report();
67
+ return;
68
+ }
69
+ }
70
+ else if (allowed && disallowed) {
71
+ if (
72
+ micromatch.isMatch(normalizedName, disallowed, { dot: true }) ||
73
+ !micromatch.isMatch(normalizedName, allowed, { dot: true })
74
+ ) {
75
+ report();
76
+ return;
77
+ }
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Reports to ESLint.
83
+ *
84
+ * @returns {void}
85
+ */
86
+ function report () {
87
+ context.report({
88
+ node,
89
+ messageId: 'text',
90
+ data: {
91
+ name: path.relative(process.cwd(), filePath).replace(/\\/gu, '/')
92
+ }
93
+ });
94
+ }
95
+ }
96
+ })
97
+ };
@@ -0,0 +1,92 @@
1
+ # Restrict file and path names
2
+
3
+ ## Rule Details
4
+
5
+ In projects in which several developers or even teams work together, it is important that files are not simply stored anywhere. This rule ensures that defined path/file name schemes are adhered to.
6
+
7
+ Example configuration for this rule:
8
+
9
+ ```ts
10
+ 'restricted-filenames': ['error', {
11
+ basePath: './src',
12
+ allowed: [
13
+ 'components/**/index.tsx',
14
+ 'utils/{index.ts,lib/[a-z]+([a-zA-Z])?(.spec).ts}'
15
+ ],
16
+ disallowed: [
17
+ 'components/NotAllowed/index.tsx'
18
+ ]
19
+ }]
20
+ ```
21
+
22
+ Examples of **valid** file paths:
23
+
24
+ - components/MyComponent/index.tsx
25
+ - utils/index.ts
26
+ - utils/lib/myFunction.ts
27
+ - utils/lib/myFunction.spec.ts
28
+
29
+ Examples of **invalid** file paths:
30
+
31
+ - components/myComponent/index.tsx
32
+ - components/myComponent/index.ts
33
+ - components/MyComponent/subfolder/index.tsx
34
+ - components/NotAllowed/index.tsx
35
+ - utils/index.tsx
36
+ - utils/helper.ts
37
+ - utils/helper/index.ts
38
+ - utils/lib/MyFunction.ts
39
+ - utils/lib/my-function.ts
40
+ - utils/lib/myFunction.js
41
+ - utils/lib/myFunction.test.ts
42
+
43
+ ### Priority of `allowed` and `disallowed`
44
+
45
+ If only `allowed` is set, all unspecified files are disallowed.
46
+
47
+ If only `disallowed` is set, all unspecified files are allowed.
48
+
49
+ If both are set, `disallowed` wins over `allowed` and all unspecified files are disallowed.
50
+
51
+ ## Glob patterns for different casings
52
+
53
+ | Name | Example | Glob pattern |
54
+ |-|-|-|
55
+ Snake case | number_of_donuts | `[a-z]*(*([a-z0-9])_+([a-z0-9]))` |
56
+ Screaming snake case | NUMBER_OF_DONUTS | `[A-Z]*(*([A-Z0-9])_+([A-Z0-9]))` |
57
+ Kebab case | number-of-donuts | `[a-z]*(*([a-z0-9])-+([a-z0-9]))` |
58
+ Camel case | numberOfDonuts | `[a-z]*([a-zA-Z0-9])` |
59
+ Pascal case | NumberOfDonuts | `[A-Z]*([a-zA-Z0-9])` |
60
+
61
+ ## Glob pattern templates
62
+
63
+ Instead of defining the same complex patterns over and over again, e.g. for casing, you can write them into a variable and use them within the pattern, for example by using template strings.
64
+
65
+ Example of `.eslintrc.js`:
66
+
67
+ ```ts
68
+ const casing = {
69
+ snake: '[a-z]*(*([a-z0-9])_+([a-z0-9]))',
70
+ screamingSnake: '[A-Z]*(*([A-Z0-9])_+([A-Z0-9]))',
71
+ kebab: '[a-z]*(*([a-z0-9])-+([a-z0-9]))',
72
+ camel: '[a-z]*([a-zA-Z0-9])',
73
+ pascal: '[A-Z]*([a-zA-Z0-9])'
74
+ };
75
+
76
+ module.exports = {
77
+ rules: {
78
+ 'restricted-filenames': ['error', {
79
+ basePath: './src',
80
+ allowed: [
81
+ `components/${casing.pascal}/index.tsx`,
82
+ `utils/{index.ts,lib/${casing.camel}?(.spec).ts}`
83
+ ]
84
+ }]
85
+ }
86
+ };
87
+ ```
88
+
89
+ ## Further Reading
90
+
91
+ See [Glob Tool - Test globs against sets of test strings quickly and easily online](https://www.digitalocean.com/community/tools/glob)
92
+ See [micromatch - The used Glob matching library](https://www.npmjs.com/package/micromatch)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linter-bundle",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "Ready-to use bundle of linting tools, containing configurations for ESLint, stylelint and markdownlint.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -32,35 +32,35 @@
32
32
  "publish:major": "npm version major",
33
33
  "publish:minor": "npm version minor",
34
34
  "publish:patch": "npm version patch",
35
- "lint": "npm run validate-stylelint-options && npm run stylelint-find-rules && node ./lint tsc ts md audit --min-severity=critical",
35
+ "lint": "npm run _validate-stylelint-options && npm run _stylelint-find-rules && node ./lint tsc ts md audit --min-severity=critical",
36
36
  "preversion": "npm run check-outdated && npm run lint",
37
37
  "postversion": "git push && git push --tags && npm publish",
38
- "stylelint-find-rules": "stylelint-find-new-rules ./stylelint/index.js",
39
- "validate-stylelint-options": "node ./validate-stylelint-options.mjs",
40
- "check-outdated": "npx --yes -- check-outdated --ignore-pre-releases"
38
+ "check-outdated": "npx --yes -- check-outdated --ignore-pre-releases",
39
+ "_stylelint-find-rules": "stylelint-find-new-rules ./stylelint/index.js",
40
+ "_validate-stylelint-options": "node ./validate-stylelint-options.mjs"
41
41
  },
42
42
  "dependencies": {
43
- "@typescript-eslint/eslint-plugin": "6.3.0",
44
- "@typescript-eslint/parser": "6.3.0",
45
- "@typescript-eslint/utils": "6.3.0",
46
- "eslint": "8.47.0",
43
+ "@typescript-eslint/eslint-plugin": "6.4.1",
44
+ "@typescript-eslint/parser": "6.4.1",
45
+ "@typescript-eslint/utils": "6.4.1",
46
+ "eslint": "8.48.0",
47
47
  "eslint-import-resolver-typescript": "3.6.0",
48
- "eslint-import-resolver-webpack": "0.13.4",
48
+ "eslint-import-resolver-webpack": "0.13.7",
49
49
  "eslint-plugin-eslint-comments": "3.2.0",
50
50
  "eslint-plugin-functional": "6.0.0",
51
- "eslint-plugin-import": "2.28.0",
51
+ "eslint-plugin-import": "2.28.1",
52
52
  "eslint-plugin-jest": "27.2.3",
53
- "eslint-plugin-jsdoc": "46.4.6",
53
+ "eslint-plugin-jsdoc": "46.5.0",
54
54
  "eslint-plugin-jsx-a11y": "6.7.1",
55
- "eslint-plugin-n": "16.0.1",
55
+ "eslint-plugin-n": "16.0.2",
56
56
  "eslint-plugin-promise": "6.1.1",
57
- "eslint-plugin-react": "7.33.1",
57
+ "eslint-plugin-react": "7.33.2",
58
58
  "eslint-plugin-react-hooks": "4.6.0",
59
59
  "eslint-plugin-unicorn": "48.0.1",
60
60
  "markdownlint-cli": "0.35.0",
61
61
  "micromatch": "4.0.5",
62
- "postcss-scss": "4.0.6",
63
- "stylelint": "15.10.2",
62
+ "postcss-scss": "4.0.7",
63
+ "stylelint": "15.10.3",
64
64
  "stylelint-declaration-block-no-ignored-properties": "2.7.0",
65
65
  "stylelint-order": "6.0.3",
66
66
  "stylelint-scss": "5.1.0",
@@ -73,8 +73,8 @@
73
73
  "devDependencies": {
74
74
  "@types/eslint": "8.44.2",
75
75
  "@types/micromatch": "4.0.2",
76
- "@types/node": "20.4.9",
77
- "stylelint-find-new-rules": "4.1.0",
78
- "typescript": "5.1.6"
76
+ "@types/node": "20.5.7",
77
+ "stylelint-find-new-rules": "4.1.1",
78
+ "typescript": "5.2.2"
79
79
  }
80
80
  }