Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Fix Flow usage
Browse files Browse the repository at this point in the history
The initial stages of Flow in here were woefully incomplete. This brings
things to a state where flow is at least checking a majority of the main
file and has basic definitions of the used modules.
  • Loading branch information
Arcanemagus committed May 3, 2017
1 parent 2423ed9 commit f83a46a
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Expand Up @@ -4,7 +4,7 @@
[include]

[libs]
decls

[options]
module.system=node
suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore
5 changes: 4 additions & 1 deletion .travis.yml
@@ -1,19 +1,22 @@
### Project specific config ###
language: generic
language: node_js

matrix:
include:
- os: linux
env: ATOM_CHANNEL=stable
node_js: "node"

- os: linux
env: ATOM_CHANNEL=beta
node_js: "node"

### Generic setup follows ###
script:
- curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh
- chmod u+x build-package.sh
- ./build-package.sh
- npm run lint

notifications:
email:
Expand Down
13 changes: 8 additions & 5 deletions circle.yml
@@ -1,10 +1,13 @@
test:
dependencies:
override:
- curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh
- chmod u+x build-package.sh
- ./build-package.sh

dependencies:
test:
override:
# If nothing is put here, CircleCI will run `npm install` using the system Node.js
- echo "Managed in the script"
- ./build-package.sh
- npm run lint

machine:
node:
version: 6.3.0
6 changes: 6 additions & 0 deletions decls/.eslintrc.js
@@ -0,0 +1,6 @@
module.exports = {
rules: {
'no-unused-vars': 'off',
'no-undef': 'off'
}
}
29 changes: 29 additions & 0 deletions decls/atom-linter.js
@@ -0,0 +1,29 @@
// @flow

/* eslint-disable import/extensions, import/no-extraneous-dependencies */
import type { TextEditor } from 'atom';
/* eslint-enable import/extensions, import/no-extraneous-dependencies */

declare type ExecOptions = {
timeout?: number,
stream?: 'stdout' | 'stderr' | 'both',
env?: Object,
stdin?: string | Buffer,
local?: {
directory: string,
prepend?: boolean
},
throwOnStderr?: boolean,
allowEmptyStderr?: boolean,
ignoreExitCode?: boolean
}

declare module 'atom-linter' {
declare var findCachedAsync:
(directory: string, names: string | Array<string>) => Promise<?string>;
declare var execNode:
(filePath: string, args: Array<string>, options: ExecOptions) => Promise<string>;
declare var generateRange:
(textEditor: TextEditor, lineNumber?: number, colStart?: number) =>
Array<Array<number>>
}
5 changes: 5 additions & 0 deletions decls/atom-package-deps.js
@@ -0,0 +1,5 @@
// @flow

declare module 'atom-package-deps' {
declare var install: (name: string) => void;
}
30 changes: 30 additions & 0 deletions decls/atom.js
@@ -0,0 +1,30 @@
// @flow

declare var atom: Object;

declare class Disposable {
dispose(): void;
}

declare module 'atom' {
declare class CompositeDisposable {
add(...observable: Array<Disposable>): void;
}

declare type Buffer = {
getLineCount: () => number,
lineLengthForRow: () => number,
}

declare type TextEditor = {
getPath: () => string,
getText: () => string,
getGrammar: () => {
scopeName: string
},
getBuffer: () => Buffer,
// setCursorBufferPosition: (point: Point) => void,
// scrollToCursorPosition: () => void,
// onDidStopChanging: (cb: () => void) => any
}
}
5 changes: 5 additions & 0 deletions decls/jshint-json.js
@@ -0,0 +1,5 @@
// @flow

declare module 'jshint-json' {
declare module.exports: string;
}
6 changes: 4 additions & 2 deletions lib/main.js
Expand Up @@ -3,8 +3,10 @@
/* @flow */

import Path from 'path';
// eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
/* eslint-disable import/extensions, import/no-extraneous-dependencies */
import { CompositeDisposable } from 'atom';
import type { TextEditor } from 'atom';
/* eslint-enable import/extensions, import/no-extraneous-dependencies */

module.exports = {
config: {
Expand Down Expand Up @@ -76,7 +78,7 @@ module.exports = {
grammarScopes: this.scopes,
scope: 'file',
lintOnFly: true,
lint: async (textEditor) => {
lint: async (textEditor: TextEditor) => {
const results = [];
const filePath = textEditor.getPath();
const fileContents = textEditor.getText();
Expand Down
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"scripts": {
"test": "apm test",
"lint": "eslint ."
"lint": "eslint lib spec decls && flow check"
},
"package-deps": [
"linter"
Expand All @@ -19,11 +19,14 @@
"jshint-json": "^1.0.0"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"eslint": "^3.12.0",
"eslint-config-airbnb-base": "^11.0.0",
"eslint-plugin-import": "^2.2.0"
"eslint-plugin-import": "^2.2.0",
"flow-bin": "^0.45.0"
},
"eslintConfig": {
"parser": "babel-eslint",
"rules": {
"global-require": "off",
"import/no-unresolved": [
Expand Down

0 comments on commit f83a46a

Please sign in to comment.