Il 08/04/2013 11:30, Holger Hans Peter Freyther ha scritto: > The category of classes and extensions should match the package > name. Create a small class that is checking this on a package and > print the errors.
I think this should be a new tool, not part of the package. You can create "gst-lint --monticello" and we can later add more lint modules. Paolo > 2013-03-30 Holger Hans Peter Freyther <[email protected]> > > * Lint/Monticello.st: Added Monticello class for linting. > * Parser/EmittedClass.st: Reimplement >>#isEmittedClass, > >>#methodsToEmit, > >>#classMethodsToEmit, #>>isComplete. > * Parser/EmittedEntity.st: Added >>#isEmittedClass. > * Parser/Loader.st: Add >>#stuffToEmit selector. > * TODO: Add work item. > * package.xml: Add the Lint/Monticello.st. > --- > packages/tooling/ChangeLog | 10 ++ > packages/tooling/Lint/Monticello.st | 151 > ++++++++++++++++++++++++++++++ > packages/tooling/Makefile.frag | 2 +- > packages/tooling/Parser/EmittedClass.st | 20 ++++ > packages/tooling/Parser/EmittedEntity.st | 4 + > packages/tooling/Parser/Loader.st | 5 + > packages/tooling/TODO | 11 +++ > packages/tooling/package.xml | 2 + > 8 files changed, 204 insertions(+), 1 deletion(-) > create mode 100644 packages/tooling/Lint/Monticello.st > > diff --git a/packages/tooling/ChangeLog b/packages/tooling/ChangeLog > index 8c85f31..a1a8760 100644 > --- a/packages/tooling/ChangeLog > +++ b/packages/tooling/ChangeLog > @@ -1,5 +1,15 @@ > 2013-03-30 Holger Hans Peter Freyther <[email protected]> > > + * Lint/Monticello.st: Added Monticello class for linting. > + * Parser/EmittedClass.st: Reimplement >>#isEmittedClass, > >>#methodsToEmit, > + >>#classMethodsToEmit, #>>isComplete. > + * Parser/EmittedEntity.st: Added >>#isEmittedClass. > + * Parser/Loader.st: Add >>#stuffToEmit selector. > + * TODO: Add work item. > + * package.xml: Add the Lint/Monticello.st. > + > +2013-03-30 Holger Hans Peter Freyther <[email protected]> > + > * Makefile.frag: Added. > * Parser/EmittedClass.st: Added from scripts/Convert.st. > * Parser/EmittedComments.st: Added from scripts/Convert.st. > diff --git a/packages/tooling/Lint/Monticello.st > b/packages/tooling/Lint/Monticello.st > new file mode 100644 > index 0000000..3c7a45c > --- /dev/null > +++ b/packages/tooling/Lint/Monticello.st > @@ -0,0 +1,151 @@ > +"====================================================================== > +| > +| Linting for Monticello export > +| > +| > + ======================================================================" > + > +"====================================================================== > +| > +| Copyright 2013 Free Software Foundation, Inc. > +| Written by Holger Hans Peter Freyther. > +| > +| This file is part of the GNU Smalltalk class library. > +| > +| The GNU Smalltalk class library is free software; you can redistribute it > +| and/or modify it under the terms of the GNU Lesser General Public License > +| as published by the Free Software Foundation; either version 2.1, or (at > +| your option) any later version. > +| > +| The GNU Smalltalk class library is distributed in the hope that it will be > +| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of > +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser > +| General Public License for more details. > +| > +| You should have received a copy of the GNU Lesser General Public License > +| along with the GNU Smalltalk class library; see the file COPYING.LIB. > +| If not, write to the Free Software Foundation, 59 Temple Place - Suite > +| 330, Boston, MA 02110-1301, USA. > +| > + ======================================================================" > + > + > +Tooling.EmittedClass extend [ > + isComplete [ > + <category: 'accessing'> > + ^ isComplete > + ] > + > + methodsToEmit [ > + <category: 'accessing'> > + ^ methodsToEmit > + ] > + > + classMethodsToEmit [ > + <category: 'accessing'> > + ^ classMethodsToEmit > + ] > + > + isComplete [ > + <category: 'accessing'> > + ^ isComplete > + ] > +] > + > +Object subclass: Monticello [ > + | loader package errors | > + <category: 'Tooling-Lint-Monticello'> > + > + Monticello class >> lint: aPackage [ > + "Work on a given package." > + ^ self new > + loadPackage: aPackage; > + lint. > + ] > + > + loadPackage: aPackage [ > + package := aPackage. > + loader := Tooling.Loader new. > + > + self lintFiles: aPackage fileIns. > + aPackage test ifNotNil: [ > + self lintFiles: aPackage test fileIns]. > + ] > + > + lintFiles: aList [ > + | files | > + > + files := package fullPathsOf: aList. > + files do: [:each | | file | > + file := each open: FileStream read. > + loader parseSmalltalkStream: file with: STInST.GSTFileInParser. > + file close. > + ] > + ] > + > + loader [ > + <category: 'private'> > + ^ loader > + ] > + > + lint [ > + <category: 'lint'> > + "TODO: this should use the visitor..." > + loader stuffToEmit do: [:each | > + each isEmittedClass ifTrue: [self lintClass: each]]. > + ] > + > + lintClass: aClass [ > + <category: 'lint'> > + aClass isComplete > + ifTrue: [self lintCompleteClass: aClass] > + ifFalse: [self lintExtension: aClass]. > + ] > + > + lintCompleteClass: aClass [ > + <category: 'lint'> > + "Check if the package name is in the category" > + (aClass forClass category startsWith: package name) > + ifFalse: [self addError: 'Class does not begin with package name' > + for: aClass forClass]. > + ] > + > + lintExtension: aClass [ > + <category: 'lint'> > + > + aClass methodsToEmit do: [:each | > + self lintExtensionMethod: each on: aClass]. > + aClass classMethodsToEmit do: [:each | > + self lintExtensionMethod: each on: aClass ]. > + ] > + > + lintExtensionMethod: aSymbol on: aClass [ > + | method | > + <category: 'lint'> > + method := aClass forClass >> aSymbol. > + (method methodCategory startsWith: ('*', package name)) > + ifFalse: [self addError: 'Method does not beging with > *package-name' > + for: aClass forClass method: aSymbol]. > + ] > + > + addError: aString for: aClass method: aMethod [ > + <category: 'error-handling'> > + self errors add: '%1 on %2>>%3' % {aString. aClass name asString. > aMethod}. > + ] > + > + addError: aString for: aClass [ > + <category: 'error-handling'> > + self errors add: '%1 on %2' % {aString. aClass name asString}. > + ] > + > + errors [ > + <category: 'error-handling'> > + ^ errors ifNil: [errors := OrderedCollection new]. > + ] > + > + printErrors [ > + <category: 'error-handling'> > + self errors do: [:each | > + Transcript nextPutAll: each; nl.] > + ] > +] > diff --git a/packages/tooling/Makefile.frag b/packages/tooling/Makefile.frag > index 01d8d86..0083a52 100644 > --- a/packages/tooling/Makefile.frag > +++ b/packages/tooling/Makefile.frag > @@ -1,5 +1,5 @@ > Tooling_FILES = \ > -packages/tooling/Parser/EmittedEntity.st > packages/tooling/Parser/EmittedClass.st > packages/tooling/Parser/EmittedComments.st > packages/tooling/Parser/EmittedEval.st packages/tooling/Parser/Loader.st > packages/tooling/Lint/Monticello.st > +packages/tooling/Parser/EmittedEntity.st > packages/tooling/Parser/EmittedClass.st > packages/tooling/Parser/EmittedComments.st > packages/tooling/Parser/EmittedEval.st packages/tooling/Parser/Loader.st > packages/tooling/Lint/Monticello.st > $(Tooling_FILES): > $(srcdir)/packages/tooling/stamp-classes: $(Tooling_FILES) > touch $(srcdir)/packages/tooling/stamp-classes > diff --git a/packages/tooling/Parser/EmittedClass.st > b/packages/tooling/Parser/EmittedClass.st > index 9a2cb13..0db74eb 100644 > --- a/packages/tooling/Parser/EmittedClass.st > +++ b/packages/tooling/Parser/EmittedClass.st > @@ -82,4 +82,24 @@ EmittedEntity subclass: EmittedClass [ > completeFileOut: isComplete; > fileOutSelectors: methodsToEmit classSelectors: > classMethodsToEmit. > ] > + > + isEmittedClass [ > + <category: 'accessing'> > + ^ true > + ] > + > + methodsToEmit [ > + <category: 'accessing'> > + ^ methodsToEmit > + ] > + > + classMethodsToEmit [ > + <category: 'accessing'> > + ^ classMethodsToEmit > + ] > + > + isComplete [ > + <category: 'accessing'> > + ^ isComplete > + ] > ] > diff --git a/packages/tooling/Parser/EmittedEntity.st > b/packages/tooling/Parser/EmittedEntity.st > index aeb6928..9bdcf73 100644 > --- a/packages/tooling/Parser/EmittedEntity.st > +++ b/packages/tooling/Parser/EmittedEntity.st > @@ -36,4 +36,8 @@ Object subclass: EmittedEntity [ > emitTo: aStream filteredBy: aBlock [ > self subclassResponsibility > ] > + > + isEmittedClass [ > + ^ false > + ] > ] > diff --git a/packages/tooling/Parser/Loader.st > b/packages/tooling/Parser/Loader.st > index 6b64301..c8fb0ec 100644 > --- a/packages/tooling/Parser/Loader.st > +++ b/packages/tooling/Parser/Loader.st > @@ -232,4 +232,9 @@ STInST.STClassLoader subclass: Loader [ > ifTrue: [ stuffToEmit last addMethod: aMethod ] > ifFalse: [ stuffToEmit add: ((EmittedClass forExtension: > currentClass) addMethod: aMethod) ] > ] > + > + stuffToEmit [ > + <category: 'accessing'> > + ^ stuffToEmit > + ] > ] > diff --git a/packages/tooling/TODO b/packages/tooling/TODO > index bc29fe6..193c08a 100644 > --- a/packages/tooling/TODO > +++ b/packages/tooling/TODO > @@ -1,2 +1,13 @@ > * Make the Loader have a Converter subclass and use a Visitor instead > of the calls to emitTo:. > + > +* The following is shown as a a single class > + Object subclass: Foo [ > + signal [] > + ] > + > + Foo extend [ > + signalTwo [] > + ] > + > + It should be two EmittedClass > diff --git a/packages/tooling/package.xml b/packages/tooling/package.xml > index ff3c23f..2bda19d 100644 > --- a/packages/tooling/package.xml > +++ b/packages/tooling/package.xml > @@ -8,4 +8,6 @@ > <filein>Parser/EmittedComments.st</filein> > <filein>Parser/EmittedEval.st</filein> > <filein>Parser/Loader.st</filein> > + > + <filein>Lint/Monticello.st</filein> > </package> > _______________________________________________ help-smalltalk mailing list [email protected] https://lists.gnu.org/mailman/listinfo/help-smalltalk
