-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
160 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports = { | ||
parserOptions: { | ||
ecmaVersion: 6 | ||
ecmaVersion: 2022 | ||
}, | ||
env: { | ||
es6: true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/no-computed-class-fields.md → docs/no-computed-public-class-fields.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# no-dynamic-import | ||
# no-dynamic-imports | ||
|
||
This prevents the use of Dynamic Imports. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* globals describe, it*/ | ||
const config = require('../lib/index') | ||
const fs = require('fs') | ||
const assert = require('assert') | ||
const path = require('path') | ||
const docDir = './docs' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const ruleTester = new RuleTester({env: {es2020: true}, parserOptions: {sourceType: 'module'}}) | ||
|
||
function rulesFromDir(dir) { | ||
try { | ||
return fs.readdirSync(`./${dir}`).map(f => path.basename(f, path.extname(f))) | ||
} catch { | ||
return [] | ||
} | ||
} | ||
|
||
function* extractCodeblocks(lines) { | ||
let inCodeBlock = false | ||
let codeLines = [] | ||
let startLine = 0 | ||
let endLine = 0 | ||
let lang = '' | ||
for (const i in lines) { | ||
const line = lines[i] | ||
if (!inCodeBlock && line.startsWith('```')) { | ||
lang = line.slice(3) | ||
startLine = i | ||
codeLines = [] | ||
inCodeBlock = true | ||
continue | ||
} else if (inCodeBlock && line.startsWith('```')) { | ||
endLine = i | ||
yield {code: codeLines, startLine, endLine, lang} | ||
inCodeBlock = false | ||
continue | ||
} | ||
if (inCodeBlock) { | ||
codeLines.push(line) | ||
} | ||
} | ||
} | ||
|
||
describe('smoke tests', () => { | ||
it('has file for each exported rule and rule for each exported file', () => { | ||
assert.deepStrictEqual( | ||
Object.keys(config.rules).sort(), | ||
rulesFromDir('lib/rules').sort(), | ||
'Expected lib/rules/*.js to be inside lib/index.js#rules' | ||
) | ||
}) | ||
|
||
for (const flavour in config.configs) { | ||
describe(`${flavour} config`, () => { | ||
it('exports valid rules', () => { | ||
const exportedRules = new Set(Object.keys(config.rules)) | ||
const ceRules = Object.keys(config.configs[flavour].rules || []).filter(rule => rule.startsWith('escompat/')) | ||
const violations = ceRules.filter(rule => !exportedRules.has(rule.replace(/^escompat\//, ''))) | ||
assert.deepStrictEqual(violations, [], 'All custom-elements/ rules should exist in lib/index.js#rules') | ||
}) | ||
}) | ||
} | ||
}) | ||
|
||
describe('test coverage', () => { | ||
it('has tests for each rule and rules for each test', () => { | ||
const tests = rulesFromDir('test').filter(name => name !== 'check-rules') | ||
assert.deepStrictEqual(rulesFromDir('lib/rules'), tests, 'Expected lib/rules/*.js to have same files as test/*.js') | ||
}) | ||
}) | ||
|
||
describe('documentation', () => { | ||
it('has rule for each doc file and doc file for each rule', () => { | ||
assert.deepStrictEqual(rulesFromDir(docDir), rulesFromDir('lib/rules')) | ||
}) | ||
|
||
it('has readme link to each doc', () => { | ||
const contents = fs.readFileSync(`./README.md`, 'utf-8').split('\n') | ||
const i = contents.indexOf('## Rules') | ||
let n = contents.findIndex((line, index) => index > i && line.startsWith('#')) | ||
if (n < i) n = contents.length | ||
const ruleLinks = contents | ||
.slice(i + 1, n) | ||
.filter(Boolean) | ||
.map(x => x.trim()) | ||
const desiredRuleLinks = rulesFromDir(docDir).map(rule => `- [${rule}](${docDir}/${rule}.md)`) | ||
assert.deepStrictEqual(desiredRuleLinks, ruleLinks, `Expected each rule in ${docDir}/*.md to have README link`) | ||
}) | ||
|
||
for (const doc of rulesFromDir(docDir)) { | ||
it(`has correct headings in ${doc}.md`, () => { | ||
const contents = fs.readFileSync(`${docDir}/${doc}.md`, 'utf-8').split('\n') | ||
let consume = true | ||
const headings = contents.filter(line => { | ||
// Discard lines that aren't headers or thumbs | ||
if (!(line.startsWith('#') || line.startsWith('\ud83d'))) return false | ||
// Ignore all sub headings/thumbs between `### Options` and `## When Not To Use It` | ||
if (line === '### Options') { | ||
consume = false | ||
return true | ||
} else if (line === '## When Not To Use It') { | ||
consume = true | ||
} | ||
return consume | ||
}) | ||
const desiredHeadings = [ | ||
`# ${doc}`, | ||
'## What is the Fix?', | ||
].filter(Boolean) | ||
assert.deepStrictEqual(headings, desiredHeadings, 'Expected doc to have correct headings') | ||
}) | ||
|
||
it(`has working examples in ${doc}.md`, () => { | ||
const rules = {valid: [], invalid: []} | ||
const lines = fs.readFileSync(`${docDir}/${doc}.md`, 'utf-8').split('\n') | ||
|
||
for (const {code, startLine} of extractCodeblocks(lines)) { | ||
const validIndex = lines.lastIndexOf('👍 Examples of **correct** code for this rule:', startLine) | ||
const invalidIndex = lines.lastIndexOf('👎 Examples of **incorrect** code for this rule:', startLine) | ||
|
||
if (validIndex === invalidIndex) { | ||
continue | ||
} | ||
|
||
let filename = '' | ||
if (code[0].match(/\s*\/\/ .*\.[jt]s$/)) { | ||
filename = code[0].replace('// ', '').trim() | ||
} | ||
|
||
if (validIndex > invalidIndex) { | ||
rules.valid.push({code: code.join('\n')}) | ||
} else { | ||
rules.invalid.push({code: code.join('\n'), errors: 1, filename}) | ||
} | ||
} | ||
|
||
const rule = require(`../lib/rules/${doc}`) | ||
ruleTester.run(doc, rule, rules) | ||
}) | ||
|
||
it(`has javascript examples in ${doc}.md`, () => { | ||
const lines = fs.readFileSync(`${docDir}/${doc}.md`, 'utf-8').split('\n') | ||
for (const {lang, startLine} of extractCodeblocks(lines)) { | ||
assert.equal(lang, 'js', `Expected codeblock on line ${startLine} to equal "js"`) | ||
} | ||
}) | ||
} | ||
}) | ||
|
File renamed without changes.