eslint-plugin-primer-react 8.5.1 → 8.5.2-rc.2cdffb2

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
@@ -1,5 +1,11 @@
1
1
  # eslint-plugin-primer-react
2
2
 
3
+ ## 8.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#488](https://github.com/primer/eslint-plugin-primer-react/pull/488) [`e27c83b`](https://github.com/primer/eslint-plugin-primer-react/commit/e27c83b392a2c947b07cd40edce5c8fc587e36dd) Thanks [@siddharthkp](https://github.com/siddharthkp)! - utils/casing-matches: Prevent ReDoS vulnerability
8
+
3
9
  ## 8.5.1
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-primer-react",
3
- "version": "8.5.1",
3
+ "version": "8.5.2-rc.2cdffb2",
4
4
  "description": "ESLint rules for Primer React",
5
5
  "main": "src/index.js",
6
6
  "engines": {
@@ -0,0 +1,88 @@
1
+ const {casingMatches, availableCasings} = require('../casing-matches')
2
+
3
+ describe('casingMatches', function () {
4
+ describe('camel case', function () {
5
+ it('matches valid camelCase identifiers', function () {
6
+ expect(casingMatches('foo', 'camel')).toBe(true)
7
+ expect(casingMatches('fooBar', 'camel')).toBe(true)
8
+ expect(casingMatches('fooBarBaz', 'camel')).toBe(true)
9
+ expect(casingMatches('className', 'camel')).toBe(true)
10
+ })
11
+
12
+ it('matches camelCase with numbers', function () {
13
+ expect(casingMatches('button2', 'camel')).toBe(true)
14
+ expect(casingMatches('v1Release', 'camel')).toBe(true)
15
+ })
16
+
17
+ it('rejects numbers at the start', function () {
18
+ expect(casingMatches('2button', 'camel')).toBe(false)
19
+ })
20
+
21
+ it('rejects PascalCase', function () {
22
+ expect(casingMatches('Foo', 'camel')).toBe(false)
23
+ expect(casingMatches('FooBar', 'camel')).toBe(false)
24
+ })
25
+
26
+ it('rejects kebab-case', function () {
27
+ expect(casingMatches('foo-bar', 'camel')).toBe(false)
28
+ })
29
+ })
30
+
31
+ describe('pascal case', function () {
32
+ it('matches valid PascalCase identifiers', function () {
33
+ expect(casingMatches('Foo', 'pascal')).toBe(true)
34
+ expect(casingMatches('FooBar', 'pascal')).toBe(true)
35
+ expect(casingMatches('FooBarBaz', 'pascal')).toBe(true)
36
+ expect(casingMatches('ClassName', 'pascal')).toBe(true)
37
+ })
38
+
39
+ it('matches PascalCase with numbers', function () {
40
+ expect(casingMatches('Foo1Bar', 'pascal')).toBe(true)
41
+ expect(casingMatches('Button2', 'pascal')).toBe(true)
42
+ })
43
+
44
+ it('rejects camelCase', function () {
45
+ expect(casingMatches('foo', 'pascal')).toBe(false)
46
+ expect(casingMatches('fooBar', 'pascal')).toBe(false)
47
+ })
48
+
49
+ it('rejects kebab-case', function () {
50
+ expect(casingMatches('Foo-Bar', 'pascal')).toBe(false)
51
+ })
52
+ })
53
+
54
+ describe('kebab case', function () {
55
+ it('matches valid kebab-case identifiers', function () {
56
+ expect(casingMatches('foo', 'kebab')).toBe(true)
57
+ expect(casingMatches('foo-bar', 'kebab')).toBe(true)
58
+ expect(casingMatches('foo-bar-baz', 'kebab')).toBe(true)
59
+ expect(casingMatches('class-name', 'kebab')).toBe(true)
60
+ })
61
+
62
+ it('matches kebab-case with trailing numbers', function () {
63
+ expect(casingMatches('button-2', 'kebab')).toBe(true)
64
+ expect(casingMatches('v-1', 'kebab')).toBe(true)
65
+ })
66
+
67
+ it('rejects camelCase', function () {
68
+ expect(casingMatches('fooBar', 'kebab')).toBe(false)
69
+ })
70
+
71
+ it('rejects PascalCase', function () {
72
+ expect(casingMatches('FooBar', 'kebab')).toBe(false)
73
+ })
74
+ })
75
+
76
+ describe('invalid case type', function () {
77
+ it('throws an error for unknown case type', function () {
78
+ expect(() => casingMatches('foo', 'snake')).toThrow('Invalid case type snake')
79
+ expect(() => casingMatches('foo', 'unknown')).toThrow('Invalid case type unknown')
80
+ })
81
+ })
82
+ })
83
+
84
+ describe('availableCasings', function () {
85
+ it('exports all available casing options', function () {
86
+ expect(availableCasings).toEqual(['camel', 'pascal', 'kebab'])
87
+ })
88
+ })
@@ -1,6 +1,6 @@
1
- const camelReg = /^[a-z]+(?:[A-Z0-9][a-z0-9]+)*?$/
2
- const pascalReg = /^(?:[A-Z0-9][a-z0-9]+)+?$/
3
- const kebabReg = /^[a-z]+(?:-[a-z0-9]+)*?$/
1
+ const camelReg = /^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/
2
+ const pascalReg = /^(?:[A-Z][a-z0-9]*)+$/
3
+ const kebabReg = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/
4
4
 
5
5
  function casingMatches(name, type) {
6
6
  switch (type) {