├── .gitignore ├── src ├── tests │ ├── isCompName.test.js │ ├── tester.js │ └── validation.test.js └── index.js ├── package.json └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store -------------------------------------------------------------------------------- /src/tests/isCompName.test.js: -------------------------------------------------------------------------------- 1 | const { isCompName } = require('../index'); 2 | 3 | test('isCompName', () => { 4 | expect(isCompName('Foo')).toBe(true); 5 | expect(isCompName('foo')).toBe(false); 6 | }); 7 | -------------------------------------------------------------------------------- /src/tests/tester.js: -------------------------------------------------------------------------------- 1 | const { transform } = require('@babel/core'); 2 | const syntaxJSX = require('@babel/plugin-syntax-jsx'); 3 | const plugin = require('../index'); 4 | 5 | /** 6 | * @param {string} inputCode 7 | * @returns 8 | */ 9 | function testPlugin(inputCode) { 10 | return transform(inputCode, { 11 | plugins: [syntaxJSX, plugin], 12 | }).code; 13 | } 14 | 15 | /** 16 | * @param {string} inputCode 17 | * @returns 18 | */ 19 | function testPluginWarnOnly(inputCode) { 20 | return transform(inputCode, { 21 | plugins: [syntaxJSX, [plugin, { warnOnly: true }]], 22 | }).code; 23 | } 24 | 25 | module.exports = { 26 | testPlugin, 27 | testPluginWarnOnly, 28 | }; 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-plugin-validate-jsx-nesting", 3 | "version": "1.0.2", 4 | "description": "compile time JSX nesting validation", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "keywords": [ 10 | "jsx validator", 11 | "dom validator", 12 | "html validator" 13 | ], 14 | "author": "Manan Tank", 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/MananTank/validate-jsx-nesting.git" 18 | }, 19 | "license": "ISC", 20 | "devDependencies": { 21 | "@babel/plugin-syntax-jsx": "^7.16.7", 22 | "@types/jest": "^27.5.1", 23 | "jest": "^28.1.0" 24 | }, 25 | "dependencies": { 26 | "@babel/core": "^7.17.10", 27 | "validate-html-nesting": "^1.2.2" 28 | }, 29 | "peerDependencies": { 30 | "@babel/plugin-syntax-jsx": "latest" 31 | } 32 | } -------------------------------------------------------------------------------- /src/tests/validation.test.js: -------------------------------------------------------------------------------- 1 | const { testPlugin, testPluginWarnOnly } = require('./tester'); 2 | 3 | // validation logic is tested in `validate-html-nesting` package 4 | 5 | test('elements are tested', () => { 6 | expect(() => testPlugin('
')).toThrowError( 7 | ' ')).not.toThrow(); 16 | expect(() => testPlugin('