Skip to content

Commit 9b03ded

Browse files
author
Naomi Carrigan
authored
chore: enable linting in workflow (#101)
* chore(tools): improve workflow file * chore: set up linter * chore: fix linter issues
1 parent 1abd4d4 commit 9b03ded

17 files changed

+1763
-1269
lines changed

.eslintrc.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"extends": [
3+
"xo",
4+
"prettier",
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/recommended"
7+
],
8+
"env": {
9+
"jest": true,
10+
"node": true
11+
},
12+
"rules": {
13+
"prettier/prettier": "error",
14+
"complexity": "off",
15+
"@typescript-eslint/no-namespace": "off",
16+
"no-warning-comments": "off",
17+
"camelcase": [
18+
"warn",
19+
{
20+
"allow": [
21+
"function_parameters",
22+
"function_body",
23+
"function_indentation"
24+
]
25+
}
26+
]
27+
},
28+
"plugins": ["prettier", "@typescript-eslint"],
29+
"parser": "@typescript-eslint/parser"
30+
}

.github/workflows/ci.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@ name: CI
22
on: pull_request
33
jobs:
44
tests:
5+
name: "Node CI"
56
runs-on: ubuntu-latest
67
steps:
78
# Checkout the Repo
89
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
910

10-
# Install Node 12
11+
# Install Node 18
1112
- name: Setup Node
1213
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e # v1
1314
with:
14-
node-version: 12
15+
node-version: 18
1516

16-
# Install dependencies
17-
- run: npm ci
17+
- name: Install Dependencies
18+
run: npm ci
1819

19-
# Run tests
20-
- run: npm test
20+
- name: Lint Files
21+
run: npm run lint
22+
23+
- name: Verify Build
24+
run: npm run build
25+
26+
- name: Run Tests
27+
run: npm test

lib/__fixtures__/curriculum-helper-css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ body {
306306

307307
const testValues = {
308308
cssFullExample,
309-
cssCodeWithCommentsRemoved
309+
cssCodeWithCommentsRemoved,
310310
};
311311

312312
export default testValues;

lib/__fixtures__/curriculum-helpers-html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ not a comment
2424

2525
const testValues = {
2626
htmlFullExample,
27-
htmlCodeWithCommentsRemoved
27+
htmlCodeWithCommentsRemoved,
2828
};
2929

3030
export default testValues;

lib/__fixtures__/curriculum-helpers-javascript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const testValues = {
6464
jsCodeWithNoCall,
6565
jsCodeWithNoArgCall,
6666
jsCodeWithArgCall,
67-
jsCodeWithCommentedCall
67+
jsCodeWithCommentedCall,
6868
};
6969

7070
export default testValues;

lib/__fixtures__/curriculum-helpers-remove-white-space.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ This string sentence has various white spaces characters:
44
\t* This line has several preceding white space characters.`;
55

66
const stringWithWhiteSpaceCharsRemoved =
7-
'Thisstringsentencehasvariouswhitespacescharacters:*Thislinestartswithatabcharacter.*Thislinehasseveralprecedingwhitespacecharacters.';
7+
"Thisstringsentencehasvariouswhitespacescharacters:*Thislinestartswithatabcharacter.*Thislinehasseveralprecedingwhitespacecharacters.";
88

99
const testValues = {
1010
stringWithWhiteSpaceChars,
11-
stringWithWhiteSpaceCharsRemoved
11+
stringWithWhiteSpaceCharsRemoved,
1212
};
1313

14-
export default testValues;
14+
export default testValues;

lib/__tests__/css-helper.test.ts

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,91 +4,91 @@
44
import { cssString } from "../__fixtures__/curriculum-helper-css";
55
import { CSSHelp } from "../index";
66

7-
describe('css-help', () => {
7+
describe("css-help", () => {
88
const doc = document;
99
let t: CSSHelp;
1010
beforeEach(() => {
11-
const style = doc.createElement('style');
11+
const style = doc.createElement("style");
1212
style.innerHTML = cssString as string;
1313
doc.head.appendChild(style);
1414
t = new CSSHelp(doc);
1515
// JSDOM does not implement latest CSSOM spec. As such,
1616
// conditionText property needs to be manually added.
1717
// REF: https://github.com/freeCodeCamp/freeCodeCamp/pull/42148#issuecomment-847291137
18-
const mediaRule = t.getCSSRules('media')?.[0] as CSSMediaRule;
18+
const mediaRule = t.getCSSRules("media")?.[0] as CSSMediaRule;
1919
const conditionText = mediaRule.media[0];
2020
mediaRule.conditionText = conditionText;
2121
});
22-
describe('getStyle', () => {
23-
it('should return an ExtendedCSSStyleDeclartion object of length 1', () => {
24-
expect(t.getStyle('*')?.length).toEqual(1);
22+
describe("getStyle", () => {
23+
it("should return an ExtendedCSSStyleDeclartion object of length 1", () => {
24+
expect(t.getStyle("*")?.length).toEqual(1);
2525
});
26-
it('should return a non-empty ExtendedCSSStyleDeclaration object', () => {
27-
expect(t.getStyle('.bb1')).toBeTruthy();
26+
it("should return a non-empty ExtendedCSSStyleDeclaration object", () => {
27+
expect(t.getStyle(".bb1")).toBeTruthy();
2828
});
29-
it('should return a whitespaceless string', () => {
30-
expect(t.getStyle('.bb1d')?.getPropVal('background', true)).toEqual(
31-
'linear-gradient(var(--building-color1)50%,var(--window-color1))'
29+
it("should return a whitespaceless string", () => {
30+
expect(t.getStyle(".bb1d")?.getPropVal("background", true)).toEqual(
31+
"linear-gradient(var(--building-color1)50%,var(--window-color1))"
3232
);
3333
});
3434
});
35-
describe('getStyleAny', () => {
36-
it('should return an ExtendedCSSStyleDeclartion object of length 1', () => {
37-
expect(t.getStyleAny(['.earth', '.sky'])?.length).toEqual(1);
35+
describe("getStyleAny", () => {
36+
it("should return an ExtendedCSSStyleDeclartion object of length 1", () => {
37+
expect(t.getStyleAny([".earth", ".sky"])?.length).toEqual(1);
3838
});
39-
it('should return null', () => {
40-
expect(t.getStyleAny(['.sun', '.earth', '.moon'])).toBeNull();
39+
it("should return null", () => {
40+
expect(t.getStyleAny([".sun", ".earth", ".moon"])).toBeNull();
4141
});
4242
});
43-
describe('isPropertyUsed', () => {
44-
it('should return true on existing properties', () => {
45-
expect(t.isPropertyUsed('height')).toBeTruthy();
43+
describe("isPropertyUsed", () => {
44+
it("should return true on existing properties", () => {
45+
expect(t.isPropertyUsed("height")).toBeTruthy();
4646
});
47-
it('should return true on existing custom properties', () => {
48-
expect(t.isPropertyUsed('--building-color1')).toBeTruthy();
47+
it("should return true on existing custom properties", () => {
48+
expect(t.isPropertyUsed("--building-color1")).toBeTruthy();
4949
});
5050
});
51-
describe('isDeclaredAfter', () => {
52-
it('should return true if existing style is declared after another', () => {
53-
expect(t.getStyleRule('.bb1a')?.isDeclaredAfter('.bb1')).toBeTruthy();
51+
describe("isDeclaredAfter", () => {
52+
it("should return true if existing style is declared after another", () => {
53+
expect(t.getStyleRule(".bb1a")?.isDeclaredAfter(".bb1")).toBeTruthy();
5454
});
5555
});
56-
describe('getPropertyValue', () => {
57-
it('should return custom property value needing trim', () => {
56+
describe("getPropertyValue", () => {
57+
it("should return custom property value needing trim", () => {
5858
expect(
59-
t.getStyle(':root')?.getPropertyValue('--building-color1')?.trim()
60-
).toEqual('#aa80ff');
59+
t.getStyle(":root")?.getPropertyValue("--building-color1")?.trim()
60+
).toEqual("#aa80ff");
6161
});
62-
it('should return value to existing property', () => {
62+
it("should return value to existing property", () => {
6363
expect(
64-
t.getStyle('.bb4a')?.getPropertyValue('background-color')
64+
t.getStyle(".bb4a")?.getPropertyValue("background-color")
6565
).toBeTruthy();
6666
});
67-
it('should return property value without evaluating result', () => {
68-
expect(t.getStyle('.bb4a')?.getPropertyValue('background-color')).toEqual(
69-
'var(--building-color4)'
67+
it("should return property value without evaluating result", () => {
68+
expect(t.getStyle(".bb4a")?.getPropertyValue("background-color")).toEqual(
69+
"var(--building-color4)"
7070
);
7171
});
7272
});
73-
describe('getCSSRules', () => {
74-
it('should return a CSSRules array of length 1', () => {
75-
expect(t.getCSSRules('media')?.length).toEqual(1);
73+
describe("getCSSRules", () => {
74+
it("should return a CSSRules array of length 1", () => {
75+
expect(t.getCSSRules("media")?.length).toEqual(1);
7676
});
7777
});
78-
describe('getRuleListsWithinMedia', () => {
79-
it('should return a CSSMediaRule array with a selectable CSSStyleRule', () => {
78+
describe("getRuleListsWithinMedia", () => {
79+
it("should return a CSSMediaRule array with a selectable CSSStyleRule", () => {
8080
expect(
8181
t
82-
.getRuleListsWithinMedia('(max-width: 1000px)')
83-
.find(x => x.selectorText === '.sky')
82+
.getRuleListsWithinMedia("(max-width: 1000px)")
83+
.find((x) => x.selectorText === ".sky")
8484
).toBeTruthy();
8585
});
86-
it('should return CSSStyleDeclaration property with complex value', () => {
86+
it("should return CSSStyleDeclaration property with complex value", () => {
8787
// NOTE: JSDOM causes value to have tabbed characters, DOM has single-line values.
8888
expect(
8989
t
90-
.getRuleListsWithinMedia('(max-width: 1000px)')
91-
.find(x => x.selectorText === '.sky')?.style?.background
90+
.getRuleListsWithinMedia("(max-width: 1000px)")
91+
.find((x) => x.selectorText === ".sky")?.style?.background
9292
).toEqual(
9393
`radial-gradient(
9494
closest-corner circle at 15% 15%,
@@ -100,28 +100,28 @@ describe('css-help', () => {
100100
);
101101
});
102102
});
103-
describe('selectorsFromSelector', () => {
104-
it('should return an empty array', () => {
103+
describe("selectorsFromSelector", () => {
104+
it("should return an empty array", () => {
105105
setupDocument();
106-
expect(t.selectorsFromSelector('.void')).toEqual([]);
106+
expect(t.selectorsFromSelector(".void")).toEqual([]);
107107
});
108-
it('should return an array with 9 members', () => {
108+
it("should return an array with 9 members", () => {
109109
setupDocument();
110-
expect(t.selectorsFromSelector('a')).toEqual([
111-
'a',
112-
'label > a',
113-
'label a',
114-
'form > label > a',
115-
'form label a',
116-
'body > form > label > a',
117-
'body form label a',
118-
'html > body > form > label > a',
119-
'html body form label a',
110+
expect(t.selectorsFromSelector("a")).toEqual([
111+
"a",
112+
"label > a",
113+
"label a",
114+
"form > label > a",
115+
"form label a",
116+
"body > form > label > a",
117+
"body form label a",
118+
"html > body > form > label > a",
119+
"html body form label a",
120120
]);
121121
});
122122

123123
function setupDocument() {
124-
const form = doc.createElement('form');
124+
const form = doc.createElement("form");
125125
form.innerHTML = `
126126
<label>
127127
<input type="checkbox" /> I accept the <a href="#">terms and conditions</a>
@@ -132,7 +132,7 @@ describe('css-help', () => {
132132
}
133133
});
134134
afterEach(() => {
135-
document.body.innerHTML = '';
136-
document.head.innerHTML = '';
135+
document.body.innerHTML = "";
136+
document.head.innerHTML = "";
137137
});
138138
});

lib/__tests__/curriculum-helper.test.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import cssTestValues from "../__fixtures__/curriculum-helper-css";
22
import htmlTestValues from "../__fixtures__/curriculum-helpers-html";
33
import jsTestValues from "../__fixtures__/curriculum-helpers-javascript";
4-
import whiteSpaceTestValues from '../__fixtures__/curriculum-helpers-remove-white-space';
4+
import whiteSpaceTestValues from "../__fixtures__/curriculum-helpers-remove-white-space";
55
import * as helper from "../index";
66

7-
const {
8-
stringWithWhiteSpaceChars,
9-
stringWithWhiteSpaceCharsRemoved
10-
} = whiteSpaceTestValues;
7+
const { stringWithWhiteSpaceChars, stringWithWhiteSpaceCharsRemoved } =
8+
whiteSpaceTestValues;
119

1210
const { cssFullExample, cssCodeWithCommentsRemoved } = cssTestValues;
1311

@@ -21,7 +19,7 @@ const {
2119
jsCodeWithNoCall,
2220
jsCodeWithNoArgCall,
2321
jsCodeWithArgCall,
24-
jsCodeWithCommentedCall
22+
jsCodeWithCommentedCall,
2523
} = jsTestValues;
2624

2725
describe("removeWhiteSpace", () => {
@@ -32,33 +30,33 @@ describe("removeWhiteSpace", () => {
3230
);
3331
});
3432

35-
it('returns a string with no white space characters', () => {
33+
it("returns a string with no white space characters", () => {
3634
expect(removeWhiteSpace(stringWithWhiteSpaceChars)).toBe(
3735
stringWithWhiteSpaceCharsRemoved
3836
);
3937
});
4038
});
4139

42-
describe('removeJSComments', () => {
40+
describe("removeJSComments", () => {
4341
const { removeJSComments } = helper;
44-
it('returns a string', () => {
42+
it("returns a string", () => {
4543
expect(typeof removeJSComments('const should = "return a string"')).toBe(
46-
'string'
44+
"string"
4745
);
4846
});
4947

50-
it('returns a string with no single or multi-line comments', () => {
48+
it("returns a string with no single or multi-line comments", () => {
5149
expect(removeJSComments(jsCodeWithSingleAndMultLineComments)).toBe(
5250
jsCodeWithSingleAndMultLineCommentsRemoved
5351
);
5452
});
5553

56-
it('leaves malformed JS unchanged', () => {
57-
const actual = '/ unclosed regex';
54+
it("leaves malformed JS unchanged", () => {
55+
const actual = "/ unclosed regex";
5856
expect(removeJSComments(actual)).toBe(actual);
5957
});
6058

61-
it('does not remove a url found in JS code', () => {
59+
it("does not remove a url found in JS code", () => {
6260
expect(removeJSComments(jsCodeWithUrl)).toBe(jsCodeWithUrlUnchanged);
6361
});
6462
});
@@ -108,4 +106,4 @@ describe("isCalledWithNoArgs", () => {
108106
it("returns false for a commented out call", () => {
109107
expect(isCalledWithNoArgs("myFunc", jsCodeWithCommentedCall)).toBe(false);
110108
});
111-
});
109+
});

0 commit comments

Comments
 (0)