Skip to content

Instantly share code, notes, and snippets.

@andrewborisov
Created May 14, 2019 09:59
Show Gist options
  • Save andrewborisov/a6f71b05f16d49b41fa75acb0ec5ce0f to your computer and use it in GitHub Desktop.
Save andrewborisov/a6f71b05f16d49b41fa75acb0ec5ce0f to your computer and use it in GitHub Desktop.
creating-ts-lint-rule project
import { lintHelper, getErrorLine } from './lint-helper';
const ruleName = 'module-imports-order';
describe('module imports order rule', () => {
it('should not fail with wrong import order', () => {
const sourceFile = `
import * as React from 'react';git push -u origin master
import { SomeGlobalModule } from '@/utils/some-util';
import { SomeGlobalModule } from '@/modules/some-global-module1';
import { SomeGlobalModule } from '@/modules/some-global-module2';
import { SomeGlobalModule } from '@/components/some-global-module3';
import { SomeLocalModule } from '../../folder/some-local-module';
import { SomeLocalModule } from '../folder/some-local-module';
import { SomeLocalModule } from './folder/some-local-module';
import '../icon.svg';
import './styles.scss';
`;
const result = lintHelper({ sourceFile, ruleName });
expect(result.errorCount).toBe(0);
});
it('should fail because of @/util/ is higher than node_module', () => {
const sourceFile = `
import { SomeGlobalModule } from '@/utils/some-util';
import * as React from 'react';
import { SomeGlobalModule } from '@/modules/some-global-module1';
import { SomeGlobalModule } from '@/modules/some-global-module2';
import { SomeGlobalModule } from '@/components/some-global-module3';
import { SomeLocalModule } from '../../folder/some-local-module';
import { SomeLocalModule } from '../folder/some-local-module';
import { SomeLocalModule } from './folder/some-local-module';
import '../icon.svg';
import './styles.scss';
`;
const result = lintHelper({ sourceFile, ruleName });
expect(result.errorCount).toBe(1);
});
// A lot of other tests in real version
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment